All files / api/module/builder builderFileHandler.ts

35.29% Statements 12/34
100% Branches 0/0
0% Functions 0/1
35.29% Lines 12/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                                              
import { handleImageFromFormData } from '@api/facade/handleImageFromFormData';
import { FormDataKey } from '@constants/form';
import { DefaultImageRestrictions, DefaultImageSize } from '@constants/image';
import { IDatabaseFile } from '@contracts/databaseFile';
import { IFormWithFiles } from '@contracts/file';
import { ResultWithValue } from '@contracts/resultWithValue';
 
export interface IBuilderImages {
  profilePicFile?: IDatabaseFile;
}
 
export const builderFileHandler = async (
  formData: IFormWithFiles,
): Promise<ResultWithValue<IBuilderImages>> => {
  const result: IBuilderImages = {};

  const profilePicResult = await handleImageFromFormData({
    fileFromForm: formData[FormDataKey.profilePicFile],
    restrictions: DefaultImageRestrictions.profilePic,
    fileName: 'profilePic',
    handlerName: 'builderFileHandler',
    ...DefaultImageSize,
  });
  if (profilePicResult.isSuccess == false) {
    return { ...profilePicResult, value: result };
  }
  result.profilePicFile = profilePicResult.value;

  return {
    isSuccess: true,
    value: result,
    errorMessage: '',
  };
};