mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
improvement: change code execution order in some services
This commit is contained in:
@@ -21,6 +21,12 @@ const ListMessagesService = async ({
|
||||
pageNumber = "1",
|
||||
ticketId
|
||||
}: Request): Promise<Response> => {
|
||||
const ticket = await ShowTicketService(ticketId);
|
||||
|
||||
if (!ticket) {
|
||||
throw new Error("No ticket found with this ID");
|
||||
}
|
||||
|
||||
const whereCondition = {
|
||||
body: where(
|
||||
fn("LOWER", col("body")),
|
||||
@@ -30,12 +36,6 @@ const ListMessagesService = async ({
|
||||
ticketId
|
||||
};
|
||||
|
||||
const ticket = await ShowTicketService(ticketId);
|
||||
|
||||
if (!ticket) {
|
||||
throw new Error("No ticket found with this ID");
|
||||
}
|
||||
|
||||
// await setMessagesAsRead(ticket);
|
||||
const limit = 20;
|
||||
const offset = limit * (+pageNumber - 1);
|
||||
|
||||
@@ -26,6 +26,15 @@ const UpdateUserService = async ({
|
||||
userData,
|
||||
userId
|
||||
}: Request): Promise<Response | undefined> => {
|
||||
const user = await User.findOne({
|
||||
where: { id: userId },
|
||||
attributes: ["name", "id", "email", "profile"]
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new AppError("No user found with this ID.", 404);
|
||||
}
|
||||
|
||||
const schema = Yup.object().shape({
|
||||
name: Yup.string().min(2),
|
||||
email: Yup.string().email(),
|
||||
@@ -40,15 +49,6 @@ const UpdateUserService = async ({
|
||||
throw new AppError(err.message);
|
||||
}
|
||||
|
||||
const user = await User.findOne({
|
||||
where: { id: userId },
|
||||
attributes: ["name", "id", "email", "profile"]
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new AppError("No user found with this ID.", 404);
|
||||
}
|
||||
|
||||
await user.update({
|
||||
email,
|
||||
password,
|
||||
|
||||
Reference in New Issue
Block a user