mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 04:09:26 +00:00
changed all models to typescript
This commit is contained in:
24
backend/src/services/TicketServices/CreateTicketService.ts
Normal file
24
backend/src/services/TicketServices/CreateTicketService.ts
Normal 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;
|
||||
74
backend/src/services/TicketServices/ListTicketsService.ts
Normal file
74
backend/src/services/TicketServices/ListTicketsService.ts
Normal 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;
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user