71 lines
1.6 KiB
TypeScript
71 lines
1.6 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!.map((user) => {
|
|
// return { uid: user.uid };
|
|
// }),
|
|
// }
|
|
userNotifications:{
|
|
create: notification.user!.map((user) => {
|
|
return {
|
|
user: {
|
|
connect: {
|
|
uid: user.uid
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
},
|
|
|
|
};
|
|
return this.model.create(createArgs);
|
|
}
|
|
|
|
/**
|
|
* @description : find unique email
|
|
*/
|
|
public async findOneByUid(uid: string) {
|
|
return this.model.findUnique({
|
|
where: {
|
|
uid: uid,
|
|
},
|
|
});
|
|
}
|
|
|
|
|
|
|
|
}
|