import PostgresDatabase from '../Infrastructure/PostgresDatabase'; import File from 'Model/Models/File'; import DatabaseService, { OnDelete, OnFind, OnUpdate } from './DatabaseService'; import FindBy from '../Types/Database/FindBy'; import DeleteBy from '../Types/Database/DeleteBy'; import NotAuthorizedException from 'Common/Types/Exception/NotAuthorizedException'; import UpdateBy from '../Types/Database/UpdateBy'; export class Service extends DatabaseService { public constructor(postgresDatabase?: PostgresDatabase) { super(File, postgresDatabase); } protected override async onBeforeUpdate( updateBy: UpdateBy ): Promise> { if (!updateBy.props.isRoot) { throw new NotAuthorizedException( 'Not authorized to update a file.' ); } return { updateBy, carryForward: null }; } protected override async onBeforeDelete( deleteBy: DeleteBy ): Promise> { if (!deleteBy.props.isRoot) { throw new NotAuthorizedException( 'Not authorized to delete a file.' ); } return { deleteBy, carryForward: null }; } protected override async onBeforeFind( findBy: FindBy ): Promise> { if (!findBy.props.isRoot) { findBy.query = { ...findBy.query, isPublic: true, }; } return { findBy, carryForward: null }; } } export default new Service();