All files / api/module/community communityModule.ts

100% Statements 34/34
100% Branches 0/0
0% Functions 0/8
100% Lines 34/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 351x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { CommunityDto } from '@contracts/dto/forms/communityDto';
import { CommunityDtoMeta } from '@contracts/dto/forms/meta/communityDto.meta';
import { cyrb53 } from '@helpers/hashHelper';
import { getDatabaseService } from '@services/external/database/databaseService';
import { Community } from '@services/external/database/xata';
import { IApiModule } from '../../types/baseModule';
import { ICommunityImages, communityFileHandler } from './communityFileHandler';
import { communityDtoWithImageToPersistence, communityPersistenceToDto } from './communityMapper';
import { communityPublicUrlHandler } from './communityPublicUrlHandler';
 
const getDbTable = () => getDatabaseService().community();
export const communityModule: IApiModule<CommunityDto, ICommunityImages, Community> = {
  segment: 'community',
  dtoMeta: CommunityDtoMeta,
  sendDiscordMessageOnSubmission: true,
  getName: (persistence: Community) => persistence.name,
  getIcon: (persistence: Community) => persistence.profilePicUrl,
 
  // Mappers
  mapDtoWithImageToPersistence: communityDtoWithImageToPersistence,
  mapPersistenceToDto: communityPersistenceToDto,
 
  // Database
  createRecord: (persistence) => getDbTable().create(persistence),
  readRecord: (id: string) => getDbTable().read(id),
  readAllRecords: () => getDbTable().readAll(),
  updateRecord: (id, persistence) => getDbTable().update(id, persistence),
 
  // Files
  handleFilesInFormData: communityFileHandler,
  getPublicUrlsOfUploads: communityPublicUrlHandler,
 
  calculateCheck: (p) => cyrb53([p.id, p.name, p.contactDetails].join('-')),
};