mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-17 19:37:02 +00:00
✨ In user registration add standard whatsapp field
This commit is contained in:
@@ -27,7 +27,7 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||
};
|
||||
|
||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
const { email, password, name, profile, queueIds } = req.body;
|
||||
const { email, password, name, profile, queueIds, whatsappId } = req.body;
|
||||
|
||||
if (
|
||||
req.url === "/signup" &&
|
||||
@@ -43,7 +43,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
password,
|
||||
name,
|
||||
profile,
|
||||
queueIds
|
||||
queueIds,
|
||||
whatsappId
|
||||
});
|
||||
|
||||
const io = getIO();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Queue from "../models/Queue";
|
||||
import User from "../models/User";
|
||||
import Whatsapp from "../models/Whatsapp";
|
||||
|
||||
interface SerializedUser {
|
||||
id: number;
|
||||
@@ -7,6 +8,7 @@ interface SerializedUser {
|
||||
email: string;
|
||||
profile: string;
|
||||
queues: Queue[];
|
||||
whatsapp: Whatsapp;
|
||||
}
|
||||
|
||||
export const SerializeUser = (user: User): SerializedUser => {
|
||||
@@ -15,6 +17,7 @@ export const SerializeUser = (user: User): SerializedUser => {
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
profile: user.profile,
|
||||
queues: user.queues
|
||||
queues: user.queues,
|
||||
whatsapp: user.whatsapp
|
||||
};
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ interface Request {
|
||||
name: string;
|
||||
queueIds?: number[];
|
||||
profile?: string;
|
||||
whatsappId?: number;
|
||||
}
|
||||
|
||||
interface Response {
|
||||
@@ -24,7 +25,8 @@ const CreateUserService = async ({
|
||||
password,
|
||||
name,
|
||||
queueIds = [],
|
||||
profile = "admin"
|
||||
profile = "admin",
|
||||
whatsappId
|
||||
}: Request): Promise<Response> => {
|
||||
const schema = Yup.object().shape({
|
||||
name: Yup.string().required().min(2),
|
||||
@@ -56,9 +58,10 @@ const CreateUserService = async ({
|
||||
email,
|
||||
password,
|
||||
name,
|
||||
profile
|
||||
profile,
|
||||
whatsappId: whatsappId ? whatsappId : null
|
||||
},
|
||||
{ include: ["queues"] }
|
||||
{ include: ["queues", "whatsapp"] }
|
||||
);
|
||||
|
||||
await user.$set("queues", queueIds);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Sequelize, Op } from "sequelize";
|
||||
import Queue from "../../models/Queue";
|
||||
import User from "../../models/User";
|
||||
import Whatsapp from "../../models/Whatsapp";
|
||||
|
||||
interface Request {
|
||||
searchParam?: string;
|
||||
@@ -39,7 +40,8 @@ const ListUsersService = async ({
|
||||
offset,
|
||||
order: [["createdAt", "DESC"]],
|
||||
include: [
|
||||
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] }
|
||||
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] },
|
||||
{ model: Whatsapp, as: "whatsapp", attributes: ["id", "name"] },
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import User from "../../models/User";
|
||||
import AppError from "../../errors/AppError";
|
||||
import Queue from "../../models/Queue";
|
||||
import Whatsapp from "../../models/Whatsapp";
|
||||
|
||||
const ShowUserService = async (id: string | number): Promise<User> => {
|
||||
const user = await User.findByPk(id, {
|
||||
attributes: ["name", "id", "email", "profile", "tokenVersion"],
|
||||
attributes: ["name", "id", "email", "profile", "tokenVersion", "whatsappId"],
|
||||
include: [
|
||||
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] }
|
||||
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] },
|
||||
{ model: Whatsapp, as: "whatsapp", attributes: ["id", "name"] },
|
||||
],
|
||||
order: [ [ { model: Queue, as: "queues"}, 'name', 'asc' ] ]
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as Yup from "yup";
|
||||
|
||||
import AppError from "../../errors/AppError";
|
||||
import { SerializeUser } from "../../helpers/SerializeUser";
|
||||
import ShowUserService from "./ShowUserService";
|
||||
|
||||
interface UserData {
|
||||
@@ -9,6 +10,7 @@ interface UserData {
|
||||
name?: string;
|
||||
profile?: string;
|
||||
queueIds?: number[];
|
||||
whatsappId?: number;
|
||||
}
|
||||
|
||||
interface Request {
|
||||
@@ -36,7 +38,7 @@ const UpdateUserService = async ({
|
||||
password: Yup.string()
|
||||
});
|
||||
|
||||
const { email, password, profile, name, queueIds = [] } = userData;
|
||||
const { email, password, profile, name, queueIds = [], whatsappId } = userData;
|
||||
|
||||
try {
|
||||
await schema.validate({ email, password, profile, name });
|
||||
@@ -48,20 +50,15 @@ const UpdateUserService = async ({
|
||||
email,
|
||||
password,
|
||||
profile,
|
||||
name
|
||||
name,
|
||||
whatsappId: whatsappId ? whatsappId : null
|
||||
});
|
||||
|
||||
await user.$set("queues", queueIds);
|
||||
|
||||
await user.reload();
|
||||
|
||||
const serializedUser = {
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
profile: user.profile,
|
||||
queues: user.queues
|
||||
};
|
||||
const serializedUser = SerializeUser(user);
|
||||
|
||||
return serializedUser;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user