80 lines
1.9 KiB
TypeScript
80 lines
1.9 KiB
TypeScript
import Database from "@Common/databases/database";
|
|
import BaseRepository from "@Repositories/BaseRepository";
|
|
import { Service } from "typedi";
|
|
import { Prisma, TotpCodes } from "@prisma/client";
|
|
import { TotpCodes as TotpCode } from "le-coffre-resources/dist/Customer";
|
|
|
|
@Service()
|
|
export default class TotpCodesRepository extends BaseRepository {
|
|
constructor(private database: Database) {
|
|
super();
|
|
}
|
|
protected get model() {
|
|
return this.database.getClient().totpCodes;
|
|
}
|
|
protected get instanceDb() {
|
|
return this.database.getClient();
|
|
}
|
|
|
|
/**
|
|
* @description : Find many totp codes
|
|
*/
|
|
public async findMany(query: Prisma.TotpCodesFindManyArgs) {
|
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
|
if (!query.include) return this.model.findMany({ ...query });
|
|
return this.model.findMany({ ...query });
|
|
}
|
|
|
|
/**
|
|
* @description : Find one totp code
|
|
*/
|
|
public async findOne(query: Prisma.TotpCodesFindFirstArgs) {
|
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
|
if (!query.include) return this.model.findFirst({ ...query });
|
|
return this.model.findFirst({ ...query });
|
|
}
|
|
|
|
/**
|
|
* @description : Create a totp code
|
|
*/
|
|
public async create(totpCode: TotpCode): Promise<TotpCodes> {
|
|
const createArgs: Prisma.TotpCodesCreateArgs = {
|
|
data: {
|
|
code: totpCode.code!,
|
|
reason: totpCode.reason!,
|
|
customer: {
|
|
connect: {
|
|
uid: totpCode.customer_uid!,
|
|
},
|
|
},
|
|
expire_at: totpCode.expire_at!,
|
|
resent: totpCode.resent!,
|
|
},
|
|
};
|
|
|
|
return this.model.create({ ...createArgs });
|
|
}
|
|
|
|
/**
|
|
* Disable a totp code
|
|
*/
|
|
public async disable(totpCode: TotpCode): Promise<TotpCodes> {
|
|
return this.model.update({
|
|
where: {
|
|
uid: totpCode.uid!,
|
|
},
|
|
data: {
|
|
expire_at: new Date(),
|
|
resent: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Delete many totp codes
|
|
*/
|
|
public async deleteMany(query: Prisma.TotpCodesDeleteManyArgs) {
|
|
return this.model.deleteMany({ ...query });
|
|
}
|
|
}
|