From 49e8f1d89b5a78d2c9b421c9d80e1b18d742a4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFs=20Mansot?= <26844641+devfull@users.noreply.github.com> Date: Fri, 29 Sep 2023 14:39:19 +0200 Subject: [PATCH] add `OfficeFolderAnchorsRepository` --- .../OfficeFolderAnchorsRepository.ts | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/common/repositories/OfficeFolderAnchorsRepository.ts diff --git a/src/common/repositories/OfficeFolderAnchorsRepository.ts b/src/common/repositories/OfficeFolderAnchorsRepository.ts new file mode 100644 index 00000000..c0687017 --- /dev/null +++ b/src/common/repositories/OfficeFolderAnchorsRepository.ts @@ -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 { + 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 { + 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, + }); + } +}