mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 04:09:26 +00:00
Migrate from moment to date-fns and some changes
This commit is contained in:
35
backend/src/routes/auth.js
Normal file
35
backend/src/routes/auth.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const express = require("express");
|
||||
const { body } = require("express-validator");
|
||||
const User = require("../models/User");
|
||||
const authController = require("../controllers/auth");
|
||||
const isAuth = require("../middleware/is-auth");
|
||||
|
||||
const routes = express.Router();
|
||||
|
||||
routes.post(
|
||||
"/signup",
|
||||
[
|
||||
body("email")
|
||||
.isEmail()
|
||||
.withMessage("Email inválido")
|
||||
.custom((value, { req }) => {
|
||||
return User.findOne({ where: { email: value } }).then(user => {
|
||||
if (user) {
|
||||
return Promise.reject("An user with this email already exists!");
|
||||
}
|
||||
});
|
||||
})
|
||||
.normalizeEmail(),
|
||||
body("password").trim().isLength({ min: 5 }),
|
||||
body("name").trim().not().isEmpty(),
|
||||
],
|
||||
authController.signup
|
||||
);
|
||||
|
||||
routes.post("/login", authController.login);
|
||||
|
||||
routes.get("/check", isAuth, (req, res) => {
|
||||
res.status(200).json({ authenticated: true });
|
||||
});
|
||||
|
||||
module.exports = routes;
|
||||
13
backend/src/routes/contacts.js
Normal file
13
backend/src/routes/contacts.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const express = require("express");
|
||||
const isAuth = require("../middleware/is-auth");
|
||||
|
||||
const ContactController = require("../controllers/contact");
|
||||
|
||||
const routes = express.Router();
|
||||
|
||||
routes.get("/contacts", isAuth, ContactController.getContacts);
|
||||
// routes.post(ContactController.postCreateContact);
|
||||
|
||||
routes.post("/contacts", isAuth, ContactController.createContact);
|
||||
|
||||
module.exports = routes;
|
||||
19
backend/src/routes/message.js
Normal file
19
backend/src/routes/message.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const express = require("express");
|
||||
const isAuth = require("../middleware/is-auth");
|
||||
|
||||
const MessangeController = require("../controllers/message");
|
||||
|
||||
const routes = express.Router();
|
||||
|
||||
routes.get(
|
||||
"/messages/:contactId",
|
||||
isAuth,
|
||||
MessangeController.getContactMessages
|
||||
);
|
||||
routes.post(
|
||||
"/messages/:contactId",
|
||||
isAuth,
|
||||
MessangeController.postCreateContactMessage
|
||||
);
|
||||
|
||||
module.exports = routes;
|
||||
22
backend/src/routes/whatsapp.js
Normal file
22
backend/src/routes/whatsapp.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const express = require("express");
|
||||
const isAuth = require("../middleware/is-auth");
|
||||
|
||||
const WhatsappController = require("../controllers/whatsapp");
|
||||
|
||||
const routes = express.Router();
|
||||
|
||||
routes.get("/whatsapp/session", isAuth, WhatsappController.getSession);
|
||||
// routes.post(
|
||||
// "/messages/:contactId",
|
||||
// isAuth,
|
||||
// WhatsappController.postCreateContactMessage
|
||||
// );
|
||||
|
||||
routes.get("/whatsapp/contacts", isAuth, WhatsappController.getContacts);
|
||||
// routes.post(
|
||||
// "/messages/:contactId",
|
||||
// isAuth,
|
||||
// WhatsappController.postCreateContactMessage
|
||||
// );
|
||||
|
||||
module.exports = routes;
|
||||
Reference in New Issue
Block a user