import { IGroup , IGroupsStorage } from "@staticdeploy/core" ; import { defaults , find , toArray } from "lodash" ; import cloneMethodsIO from "./common/cloneMethodsIO" ; import convertErrors from "./common/convertErrors" ; import { ICollection } from "./common/ICollection" ; @ cloneMethodsIO @ convertErrors export default class GroupsStorage implements IGroupsStorage { constructor ( private groups ) { } async findOne ( id ) { return this . groups [ id ] || null ; } async findOneByName ( name ) { return find ( this . groups , { name } ) || null ; } async findMany ( ) { return toArray ( this . groups ) ; } async oneExistsWithName ( name ) { return ! ! find ( this . groups , { name } ) ; } async allExistWithIds ( ids ) { return ids . every ( ( id ) => ! ! this . groups [ id ] ) ; } async createOne ( toBeCreatedGroup ) { this . groups [ toBeCreatedGroup . id ] = toBeCreatedGroup ; return toBeCreatedGroup ; } async updateOne ( id , patch ) { this . groups [ id ] = { ... this . groups [ id ] , ... defaults ( patch , this . groups [ id ] ) , } ; return this . groups [ id ] ; } async deleteOne ( id ) { delete this . groups [ id ] ; } }