Merge conflicts
<<<<<<< HEAD import { Controller, Get, Post, Body, Put, Param, Delete, Query, ParseUUIDPipe, UseInterceptors, NotFoundException, } from '@nestjs/common'; ======= import { Controller, Get, Post, Body, Put, Param, Delete, Query, ParseUUIDPipe, UseInterceptors } from '@nestjs/common'; >>>>>>> develop import { PersonService } from './person.service'; import { CreatePersonDto, UpdatePersonDto } from './dto/create-person.dto'; import { v4 as uuid } from 'uuid'; import { Person } from '@/models/person.model'; import { PersonType } from '@nietpluis/common'; import { AddressDTO, CreateContactInfoDTO, CreateDetailDto } from '../details/dto/create-detail.dto'; import { VZLogger } from '../logger/logger.service'; <<<<<<< HEAD import { Result, VerificationTokenPayload } from '@/interfaces'; import EmailService from '../email/email.service'; import { ConfigService } from '@nestjs/config'; import { JwtService } from '@nestjs/jwt'; import { NotFoundInterceptor } from '@/interceptors/not-found.interceptor'; import { Public } from '@/decorators/public'; import { ActivateAccountDto } from '../details/dto/activate-account.dto'; ======= import { Result } from '@/interfaces'; import { NotFoundInterceptor } from '@/interceptors/not-found.interceptor'; >>>>>>> develop @Controller('person') export class PersonController { constructor( private readonly personService: PersonService, private readonly mailService: EmailService, private readonly configService: ConfigService, private readonly logger: VZLogger, private readonly jwtService: JwtService ) {} private createToken(payload: VerificationTokenPayload): string { return this.jwtService.sign(payload, { secret: this.configService.get('JWT_VERIFICATION_TOKEN_SECRET'), expiresIn: this.configService.get('JWT_VERIFICATION_TOKEN_EXPIRATION_TIME'), }); } @Post() async create(@Body() body: CreatePersonDto): Promise<Person | null> { try { const id = uuid(); const addressId = uuid(); const contact: CreateContactInfoDTO[] = body.details.contact.map((info) => ({ id: uuid(), type: info.type, value: info.value, detailsId: id, })); const emailInfo = body.details.contact .filter((contactInfo) => { return contactInfo.type === 'email' ? contactInfo : undefined; }) .first(); const token = this.createToken({ email: emailInfo.value }); let gpId = null; let address: AddressDTO = null; if (body.type === 'patient') { gpId = body.details.gp.id; address = { ...body.details.address, id: addressId }; } const details: CreateDetailDto = { id, ...body.details, address, contact, gpId, token }; body.details.id = id; const newPerson = await this.personService.create({ ...body, details }); if (emailInfo) { await this.mailService.send({ to: emailInfo.value, template: 'notification/person-added', vars: { name: newPerson.details.fullName(), title: 'Welkom bij Niet Pluis', url: `${this.configService.get('BASE_URL')}/auth/email-activeren/${id}/${token}`, preheader: 'U bent toegevoegd als contactpersoon op Niet Pluis', }, }); } else { this.logger.error(`No emailaddress found for user ${id}`, 'no trace'); } return newPerson; } catch (error) { this.logger.error(error.message, error.trace); } return null; } @Get() async findAll(@Query('type') type: PersonType, @Query('open') openReports: boolean) { const results: Result<Person> = { count: 0, results: [], }; const personResults: void | Result<Person> = await this.personService .findAll(type, openReports) .catch((error) => { this.logger.error(error.message, error.trace); }); return personResults ?? results; } @Get('find') findByLastNameAndDOB( @Query('lastName') lastName: string, @Query('fistName') firstName: string, @Query('initials') initials: string, @Query('dob') dob?: string, @Query('type') type?: PersonType ) { if (dob) { return this.personService.findByLastNameAndDOB(lastName, dob); } else { return this.personService.find({ lastName, firstName, initials }, type); } } <<<<<<< HEAD @UseInterceptors(new NotFoundInterceptor('No user found for given id')) ======= @UseInterceptors(new NotFoundInterceptor('No person found for given id')) >>>>>>> develop @Get(':id') findOne(@Param('id', ParseUUIDPipe) id: string) { return this.personService.findOne(id); } @Put(':id') update(@Param('id', ParseUUIDPipe) id: string, @Body() updatePersonDto: UpdatePersonDto) { return this.personService.update(id, updatePersonDto); } @Delete(':id') remove(@Param('id', ParseUUIDPipe) id: string) { return this.personService.remove(id); } @Public() @Get('token/:token') async checkToken(@Param() token: any): Promise<boolean> { return this.personService.checkToken(token.token); } @Public() @Get('active/:id') async active(@Param('id', ParseUUIDPipe) id: string): Promise<{ active: boolean }> { return { active: await this.personService.checkIfActive(id) }; } @Public() @Post('resend-activation') async resendActivation(@Body() body: any): Promise<null> { const person = await this.personService.findByEmail(body.email); const newToken = await this.personService.updateToken(person, body.email); if (newToken) { try { await this.mailService.send({ to: body.email, template: 'notification/person-added', vars: { name: person.details.fullName(), title: 'Uw nieuwe activatie link', url: `${this.configService.get('BASE_URL')}/auth/email-activeren/${body.id}/${newToken}`, preheader: 'Er is een nieuwe activatie link voor u aangevraagd', }, }); } catch (error) { this.logger.error(error.message, error.trace); } } else { this.logger.error('Could not update token', newToken); } return null; } @Public() @Post('activate') async activateAccount(@Body() body: ActivateAccountDto): Promise<boolean> { console.log('test'); const person = await this.personService.findByIdAndToken(body.userId, body.token); if (!person) { throw new NotFoundException(); } const activateAccountDto: ActivateAccountDto = { userId: body.userId, token: body.token, }; return this.personService.activate(activateAccountDto); } }
issue