parent
6b4b16c13b
commit
28fb9834e1
@ -1,9 +1,10 @@
|
||||
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, QueryParam } from 'routing-controllers';
|
||||
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { GroupContactNotFoundError } from '../errors/GroupContactErrors';
|
||||
import { GroupContactIdsNotMatchingError, GroupContactNotFoundError } from '../errors/GroupContactErrors';
|
||||
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
||||
import { CreateGroupContact } from '../models/actions/create/CreateGroupContact';
|
||||
import { UpdateGroupContact } from '../models/actions/update/UpdateGroupContact';
|
||||
import { GroupContact } from '../models/entities/GroupContact';
|
||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
||||
import { ResponseGroupContact } from '../models/responses/ResponseGroupContact';
|
||||
@ -62,26 +63,27 @@ export class GroupContactController {
|
||||
return (await this.contactRepository.findOne({ id: contact.id }, { relations: ['groups'] })).toResponse();
|
||||
}
|
||||
|
||||
// @Put('/:id')
|
||||
// @Authorized("DONOR:UPDATE")
|
||||
// @ResponseSchema(ResponseDonor)
|
||||
// @ResponseSchema(DonorNotFoundError, { statusCode: 404 })
|
||||
// @ResponseSchema(DonorIdsNotMatchingError, { statusCode: 406 })
|
||||
// @OpenAPI({ description: "Update the contact whose id you provided. <br> Please remember that ids can't be changed." })
|
||||
// async put(@Param('id') id: number, @Body({ validate: true }) contact: UpdateDonor) {
|
||||
// let oldDonor = await this.contactRepository.findOne({ id: id });
|
||||
@Put('/:id')
|
||||
@Authorized("CONTACT:UPDATE")
|
||||
@ResponseSchema(ResponseGroupContact)
|
||||
@ResponseSchema(GroupContactNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(GroupContactIdsNotMatchingError, { statusCode: 406 })
|
||||
@ResponseSchema(RunnerGroupNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: "Update the contact whose id you provided. <br> Please remember that ids can't be changed." })
|
||||
async put(@Param('id') id: number, @Body({ validate: true }) contact: UpdateGroupContact) {
|
||||
let oldContact = await this.contactRepository.findOne({ id: id });
|
||||
|
||||
// if (!oldDonor) {
|
||||
// throw new DonorNotFoundError();
|
||||
// }
|
||||
if (!oldContact) {
|
||||
throw new GroupContactNotFoundError();
|
||||
}
|
||||
|
||||
// if (oldDonor.id != contact.id) {
|
||||
// throw new DonorIdsNotMatchingError();
|
||||
// }
|
||||
if (oldContact.id != contact.id) {
|
||||
throw new GroupContactIdsNotMatchingError();
|
||||
}
|
||||
|
||||
// await this.contactRepository.save(await contact.update(oldDonor));
|
||||
// return new ResponseDonor(await this.contactRepository.findOne({ id: id }, { relations: ['donations', 'donations.runner', 'donations.runner.scans', 'donations.runner.scans.track'] }));
|
||||
// }
|
||||
await this.contactRepository.save(await contact.update(oldContact));
|
||||
return (await this.contactRepository.findOne({ id: contact.id }, { relations: ['groups'] })).toResponse();
|
||||
}
|
||||
|
||||
@Delete('/:id')
|
||||
@Authorized("CONTACT:DELETE")
|
||||
|
Loading…
x
Reference in New Issue
Block a user