lecoffre-back/src/common/repositories/NotificationRepository.ts
2023-08-01 11:48:24 +02:00

74 lines
1.7 KiB
TypeScript

import Database from "@Common/databases/database";
import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { Notifications, Prisma } from "prisma/prisma-client";
import { Notification } from "le-coffre-resources/dist/SuperAdmin";
@Service()
export default class NotificationRepository extends BaseRepository {
constructor(private database: Database) {
super();
}
protected get model() {
return this.database.getClient().notifications;
}
protected get instanceDb() {
return this.database.getClient();
}
/**
* @description : Find many emails
*/
public async findMany(query: Prisma.NotificationsFindManyArgs) {
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
return this.model.findMany(query);
}
/**
* @description : Create an email
*/
public async create(notification: Notification): Promise<Notifications> {
const createArgs: Prisma.NotificationsCreateArgs = {
data: {
message: notification.message,
redirection_url: notification.redirection_url,
users: {
connect: notification.user
}
},
};
return this.model.create(createArgs);
}
/**
* @description : update given email
*/
public async update(uid: string, notification: Notifications): Promise<Notifications> {
const updateArgs: Prisma.NotificationsUpdateArgs = {
where: {
uid: uid,
},
data: {
status: notification.status,
},
};
return this.model.update(updateArgs);
}
/**
* @description : find unique email
*/
public async findOneByUid(uid: string) {
return this.model.findUnique({
where: {
uid: uid,
},
});
}
}