Skip to content
Snippets Groups Projects
Select Git revision
  • issue/275-changes
  • develop default protected
  • Issue-25/swagger
  • Issue/58-adjustments
  • 52-criar-rota-de-publicar-recurso
  • 57-rotas-s3
  • issue-49/criar-rotas-de-usuarios
  • 48-criar-rotas-de-recursos
  • issue-22/create-complaints-table
  • issue-2/translate-schemas
10 results

user-collection.service.ts

Blame
  • user-collection.service.ts 1.33 KiB
    import { userCollectionsRepo } from "@/db/repo/user-collection.repo";
    import type { CollectionModel } from "@/db/schema/collections.schema";
    import type { UserModel } from "@/db/schema/user.schema";
    import { Inject, Service } from "typedi";
    
    @Service()
    export class UserCollectionsService {
      @Inject()
      private readonly repo: userCollectionsRepo;
    
      async associateUserWithCollections(userId: UserModel['id'], collectionIds: CollectionModel['id'][]): Promise<void> {
        await this.repo.associateUserWithCollection(userId, collectionIds);
      }
    
      async getCollectionByUser(userId: UserModel['id']): Promise<Partial<CollectionModel>[]> {
        return this.repo.getCollectionsByUser(userId);
      }
    
      async removeCollectionsFromUser(userId: UserModel['id'], collectionIds: CollectionModel['id'][]): Promise<void> {
        await this.repo.removeCollectionsFromUser(userId, collectionIds);
      }
    
      async isAssociationExists(userId: UserModel['id'], collectionId: CollectionModel['id']): Promise<boolean> {
        return this.repo.isAssociationExists(userId, collectionId);
      }
    
      async getUsersByCollection(collectionId: CollectionModel['id']): Promise<UserModel[]> {
        return this.repo.getUsersByCollection(collectionId);
      }
    
      async getOwnerCollection(collectionId: CollectionModel['id']): Promise<UserModel> {
        return this.repo.getOwnerCollection(collectionId)
      }
    }