add OfficeFolderAnchorsRepository

This commit is contained in:
Loïs Mansot 2023-09-29 14:39:19 +02:00
parent f961fc6eaa
commit 49e8f1d89b
No known key found for this signature in database
GPG Key ID: 8CF1F4150DDA726D

View File

@ -0,0 +1,68 @@
import Database from "@Common/databases/database";
import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { OfficeFolderAnchors, Prisma } from "@prisma/client";
import { OfficeFolderAnchor } from "le-coffre-resources/dist/SuperAdmin";
@Service()
export default class OfficeFolderAnchorsRepository extends BaseRepository {
constructor(private database: Database) {
super();
}
protected get model() {
return this.database.getClient().officeFolderAnchors;
}
protected get instanceDb() {
return this.database.getClient();
}
/**
* @description : Create new office folder anchor
*/
public async create(officeFolderAnchor: OfficeFolderAnchor): Promise<OfficeFolderAnchors> {
const createArgs: Prisma.OfficeFolderAnchorsCreateArgs = {
data: {
hash_sources: officeFolderAnchor.hash_sources,
root_hash: officeFolderAnchor.root_hash!,
blockchain: officeFolderAnchor.blockchain as OfficeFolderAnchors["blockchain"],
status: officeFolderAnchor.status as OfficeFolderAnchors["status"],
anchor_nb_try: officeFolderAnchor.anchor_nb_try,
tx_id: officeFolderAnchor.tx_id,
tx_link: officeFolderAnchor.tx_link,
tx_hash: officeFolderAnchor.tx_hash,
anchored_at: officeFolderAnchor.anchored_at,
},
};
return this.model.create({ ...createArgs });
}
/**
* @description : Update data of an office folder anchor
*/
public async update(officeFolderAnchorUid: string, officeFolderAnchor: OfficeFolderAnchor): Promise<OfficeFolderAnchors> {
const updateArgs: Prisma.OfficeFolderAnchorsUpdateArgs = {
where: {
uid: officeFolderAnchorUid,
},
data: {
blockchain: officeFolderAnchor.blockchain as OfficeFolderAnchors["blockchain"],
status: officeFolderAnchor.status as OfficeFolderAnchors["status"],
anchor_nb_try: officeFolderAnchor.anchor_nb_try,
tx_id: officeFolderAnchor.tx_id,
tx_link: officeFolderAnchor.tx_link,
tx_hash: officeFolderAnchor.tx_hash,
anchored_at: officeFolderAnchor.anchored_at,
},
};
return this.model.update({
...updateArgs,
});
}
}