changed all models to typescript

This commit is contained in:
canove
2020-09-19 08:15:47 -03:00
parent b04c0b878e
commit 99fa2cea61
22 changed files with 629 additions and 162 deletions

View File

@@ -0,0 +1,24 @@
import * as Yup from "yup";
import AppError from "../../errors/AppError";
import User from "../../models/User";
interface Request {
email: string;
password: string;
name: string;
profile?: string;
}
interface Response {
email: string;
name: string;
id: number;
profile: string;
}
const CreateTicketService = async (): Promise<boolean> => {
return true;
};
export default CreateTicketService;

View File

@@ -0,0 +1,74 @@
import { Op } from "sequelize";
import { startOfDay, endOfDay, parseISO } from "date-fns";
import Ticket from "../../models/Ticket";
interface Request {
searchParam?: string;
pageNumber?: string;
status?: string;
date?: string;
showAll?: string;
userId: string;
}
interface Response {
tickets: Ticket[];
count: number;
hasMore: boolean;
}
const ListTicketsService = async ({
searchParam = "",
pageNumber = "1",
status,
date,
showAll,
userId
}: Request): Promise<Response> => {
let whereCondition = {};
if (showAll === "true") {
whereCondition = {};
} else {
whereCondition = { userId };
}
if (status) {
whereCondition = {
...whereCondition,
status
};
}
if (date) {
whereCondition = {
...whereCondition,
createdAt: {
[Op.between]: [startOfDay(parseISO(date)), endOfDay(parseISO(date))]
}
};
}
const limit = 20;
const offset = limit * (+pageNumber - 1);
const { count, rows: tickets } = await Ticket.findAndCountAll({
where: whereCondition,
// distinct: true,
// include: includeCondition,
limit,
offset,
order: [["updatedAt", "DESC"]]
});
const hasMore = count > offset + tickets.length;
return {
tickets,
count,
hasMore
};
};
export default ListTicketsService;

View File

@@ -28,7 +28,7 @@ const ListUsersService = async ({
{ email: { [Op.like]: `%${searchParam.toLowerCase()}%` } }
]
};
const limit = 10;
const limit = 20;
const offset = limit * (+pageNumber - 1);
const { count, rows: users } = await User.findAndCountAll({