improvement: change code execution order in some services

This commit is contained in:
canove
2020-09-24 14:27:11 -03:00
parent e1db12d545
commit 0729f25295
2 changed files with 15 additions and 15 deletions

View File

@@ -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);

View File

@@ -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,