Skip to content

Commit

Permalink
sort notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
WalissonPires committed Apr 19, 2024
1 parent 0730fd8 commit a00fd19
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/domains/notifications/use-cases/get-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UserLogged } from "@/common/auth/user";
import { PagedInput, PagedResult } from "@/common/http/pagination";
import { NotificationMapper } from "../mapper";
import { Notification1 } from "./entities";
import { DateTime } from "luxon";


export class GetNotifications implements UseCase<GetNotificationsInput, PagedResult<Notification1>> {
Expand All @@ -19,8 +20,17 @@ export class GetNotifications implements UseCase<GetNotificationsInput, PagedRes

public async execute(input: GetNotificationsInput): Promise<PagedResult<Notification1>> {

const lastHour = DateTime.now().minus({ hour: 1 });

const filter: Prisma.NotificationWhereInput = {
accountId: this._user.accountId
accountId: this._user.accountId,
OR: [{
canceledAt: null
}, {
canceledAt: {
gte: lastHour.toJSDate()
}
}]
};

if (input.isSended === true) {
Expand Down Expand Up @@ -58,9 +68,9 @@ export class GetNotifications implements UseCase<GetNotificationsInput, PagedRes
}
},
orderBy: [{
scheduledAt: 'desc'
sendedAt: 'desc',
}, {
createdAt: 'asc'
scheduledAt: 'asc'
}]
});

Expand Down

0 comments on commit a00fd19

Please sign in to comment.