mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 04:09:26 +00:00
📂Better folder structures and file names in backend
This commit is contained in:
@@ -4,7 +4,7 @@ const Sequelize = require("sequelize");
|
||||
const { getIO } = require("../libs/socket");
|
||||
const { getWbot } = require("../libs/wbot");
|
||||
|
||||
exports.getContacts = async (req, res) => {
|
||||
exports.index = async (req, res) => {
|
||||
const { searchParam = "" } = req.query;
|
||||
|
||||
const lowerSerachParam = searchParam.toLowerCase();
|
||||
@@ -43,7 +43,7 @@ exports.getContacts = async (req, res) => {
|
||||
return res.json(contacts);
|
||||
};
|
||||
|
||||
exports.createContact = async (req, res) => {
|
||||
exports.store = async (req, res) => {
|
||||
const wbot = getWbot();
|
||||
const io = getIO();
|
||||
const { number, name } = req.body;
|
||||
@@ -1,4 +1,3 @@
|
||||
const fs = require("fs");
|
||||
const Message = require("../models/Message");
|
||||
const Contact = require("../models/Contact");
|
||||
const { getIO } = require("../libs/socket");
|
||||
@@ -25,7 +24,7 @@ const setMessagesAsRead = async contactId => {
|
||||
});
|
||||
};
|
||||
|
||||
exports.getContactMessages = async (req, res, next) => {
|
||||
exports.index = async (req, res, next) => {
|
||||
const wbot = getWbot();
|
||||
const io = getIO();
|
||||
|
||||
@@ -76,7 +75,7 @@ exports.getContactMessages = async (req, res, next) => {
|
||||
});
|
||||
};
|
||||
|
||||
exports.postCreateContactMessage = async (req, res, next) => {
|
||||
exports.store = async (req, res, next) => {
|
||||
const wbot = getWbot();
|
||||
const io = getIO();
|
||||
|
||||
@@ -4,26 +4,7 @@ const jwt = require("jsonwebtoken");
|
||||
|
||||
const User = require("../models/User");
|
||||
|
||||
exports.signup = async (req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
return res.status(400).json({ error: "Validation failed" });
|
||||
}
|
||||
|
||||
const { name, password, email } = req.body;
|
||||
|
||||
const hashedPw = await bcrypt.hash(password, 12);
|
||||
const user = User.build({
|
||||
email: email,
|
||||
password: hashedPw,
|
||||
name: name,
|
||||
});
|
||||
const result = await user.save();
|
||||
res.status(201).json({ message: "User created!", userId: result.id });
|
||||
};
|
||||
|
||||
exports.login = async (req, res, next) => {
|
||||
exports.store = async (req, res, next) => {
|
||||
const { email, password } = req.body;
|
||||
|
||||
const user = await User.findOne({ where: { email: email } });
|
||||
25
backend/src/controllers/UserController.js
Normal file
25
backend/src/controllers/UserController.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const { validationResult } = require("express-validator");
|
||||
const bcrypt = require("bcryptjs");
|
||||
|
||||
const User = require("../models/User");
|
||||
|
||||
exports.store = async (req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ error: "Validation failed", data: errors.array() });
|
||||
}
|
||||
|
||||
const { name, password, email } = req.body;
|
||||
|
||||
const hashedPw = await bcrypt.hash(password, 12);
|
||||
const user = User.build({
|
||||
email: email,
|
||||
password: hashedPw,
|
||||
name: name,
|
||||
});
|
||||
const result = await user.save();
|
||||
res.status(201).json({ message: "User created!", userId: result.id });
|
||||
};
|
||||
Reference in New Issue
Block a user