Skip to content

Commit

Permalink
Merge pull request #8 from mju-likelion/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
ndaemy authored Feb 15, 2023
2 parents 9c3b698 + 9bcf75d commit ba14720
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 18 deletions.
6 changes: 0 additions & 6 deletions src/api/applications/application.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type ApplicationForm = {
thirdAnswer: string;
fourthAnswer: string;
fifthAnswer: string;
sixthAnswer: string;
};

@Entity('Application')
Expand Down Expand Up @@ -74,9 +73,6 @@ export class Application {
@Column({ nullable: true })
fifthAnswer: string;

@Column({ nullable: true })
sixthAnswer: string;

@CreateDateColumn()
createdDate: Date;

Expand All @@ -98,7 +94,6 @@ export class Application {
thirdAnswer,
fourthAnswer,
fifthAnswer,
sixthAnswer,
}: ApplicationForm): Application {
const application = new Application();

Expand All @@ -117,7 +112,6 @@ export class Application {
application.thirdAnswer = thirdAnswer;
application.fourthAnswer = fourthAnswer;
application.fifthAnswer = fifthAnswer;
application.sixthAnswer = sixthAnswer;

return application;
}
Expand Down
58 changes: 57 additions & 1 deletion src/api/applications/applications.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { PutObjectCommand } from '@aws-sdk/client-s3';
import { Injectable } from '@nestjs/common';
import {
BadRequestException,
ConflictException,
Injectable,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';

Expand All @@ -17,6 +21,58 @@ export class ApplicationsService {
async create(createApplicationDto: CreateApplicationDto) {
const { personalInfo, applicationInfo } = createApplicationDto;

const conflictErrors: string[] = [];
const samePhoneUser = await this.applicationRepository.findOne({
where: {
phone: personalInfo.phone,
},
});
const sameEmailUser = await this.applicationRepository.findOne({
where: {
email: personalInfo.email,
},
});
const sameSidUser = await this.applicationRepository.findOne({
where: {
sid: personalInfo.sid,
},
});

if (samePhoneUser) {
conflictErrors.push(`phone ${personalInfo.phone} is already exist`);
}
if (sameEmailUser) {
conflictErrors.push(`email ${personalInfo.email} is already exist`);
}
if (sameSidUser) {
conflictErrors.push(`sid ${personalInfo.sid} is already exist`);
}

if (conflictErrors.length > 0) {
throw new ConflictException(conflictErrors);
}

// 디지몬 파트가 아닌데 자기소개서 페이지 파일이 없으면 400 에러
if (personalInfo.part !== 'design') {
const errors: string[] = [];

if (!applicationInfo.cvUrl) {
errors.push(
"applicationInfo.cvUrl must be exist when personalInfo.part isn't design",
);
}

if (!applicationInfo.fifthAnswer) {
errors.push(
"applicationInfo.fifthAnswer must be exist when personalInfo.part isn't design",
);
}

if (errors.length > 0) {
throw new BadRequestException(errors);
}
}

const application = Application.from({
...personalInfo,
...applicationInfo,
Expand Down
15 changes: 4 additions & 11 deletions src/api/applications/dto/create-application.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IsEmail,
IsIn,
IsObject,
IsOptional,
IsString,
IsUrl,
Matches,
Expand Down Expand Up @@ -86,14 +87,12 @@ class PersonalInfo {
readonly personalInfoAgreement: true;
}

/**
* 문항은 최대 6개일 것이라고 가정
*/
class ApplicationInfo {
@ApiProperty({
example: 'https://example.com/cv.zip',
description: '자기소개서 링크 (URL)',
})
@IsOptional()
@IsUrl()
@MaxLength(512)
readonly cvUrl: string;
Expand Down Expand Up @@ -134,17 +133,11 @@ class ApplicationInfo {
example: '다섯 번째 문항 답변입니다.',
description: '다섯 번째 문항 답변 (1000자 이하)',
})
// 디지몬 파트는 다섯 번째 문항이 없으므로 Optional
@IsOptional()
@IsString()
@MaxLength(1000)
readonly fifthAnswer: string;

@ApiProperty({
example: '여섯 번째 문항 답변입니다.',
description: '여섯 번째 문항 답변 (1000자 이하)',
})
@IsString()
@MaxLength(1000)
readonly sixthAnswer: string;
}

export class CreateApplicationDto {
Expand Down

0 comments on commit ba14720

Please sign in to comment.