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