69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
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,
|
|
});
|
|
}
|
|
}
|