parent
a9a5eb6735
commit
0379786cbd
@ -1,8 +1,9 @@
|
||||
import { Authorized, Get, JsonController, OnUndefined, Param } from 'routing-controllers';
|
||||
import { Authorized, Delete, Get, JsonController, OnUndefined, Param, QueryParam } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { GroupContactNotFoundError } from '../errors/GroupContactErrors';
|
||||
import { GroupContact } from '../models/entities/GroupContact';
|
||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
||||
import { ResponseGroupContact } from '../models/responses/ResponseGroupContact';
|
||||
|
||||
@JsonController('/contacts')
|
||||
@ -31,7 +32,7 @@ export class ContactController {
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
@Authorized("DONOR:GET")
|
||||
@Authorized("CONTACT:GET")
|
||||
@ResponseSchema(ResponseGroupContact)
|
||||
@ResponseSchema(GroupContactNotFoundError, { statusCode: 404 })
|
||||
@OnUndefined(GroupContactNotFoundError)
|
||||
@ -79,31 +80,18 @@ export class ContactController {
|
||||
// return new ResponseDonor(await this.contactRepository.findOne({ id: id }, { relations: ['donations', 'donations.runner', 'donations.runner.scans', 'donations.runner.scans.track'] }));
|
||||
// }
|
||||
|
||||
// @Delete('/:id')
|
||||
// @Authorized("DONOR:DELETE")
|
||||
// @ResponseSchema(ResponseDonor)
|
||||
// @ResponseSchema(ResponseEmpty, { statusCode: 204 })
|
||||
// @OnUndefined(204)
|
||||
// @OpenAPI({ description: 'Delete the contact whose id you provided. <br> If no contact with this id exists it will just return 204(no content). <br> If the contact still has donations associated this will fail, please provide the query param ?force=true to delete the contact with all associated donations.' })
|
||||
// async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
|
||||
// let contact = await this.contactRepository.findOne({ id: id });
|
||||
// if (!contact) { return null; }
|
||||
// const responseDonor = await this.contactRepository.findOne(contact, { relations: ['donations', 'donations.runner', 'donations.runner.scans', 'donations.runner.scans.track'] });
|
||||
@Delete('/:id')
|
||||
@Authorized("CONTACT:DELETE")
|
||||
@ResponseSchema(ResponseGroupContact)
|
||||
@ResponseSchema(ResponseEmpty, { statusCode: 204 })
|
||||
@OnUndefined(204)
|
||||
@OpenAPI({ description: 'Delete the contact whose id you provided. <br> If no contact with this id exists it will just return 204(no content). <br> This won\'t delete any groups associated with the contact.' })
|
||||
async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
|
||||
let contact = await this.contactRepository.findOne({ id: id });
|
||||
if (!contact) { return null; }
|
||||
const responseContact = await this.contactRepository.findOne(contact, { relations: ['groups'] });
|
||||
|
||||
// if (!contact) {
|
||||
// throw new DonorNotFoundError();
|
||||
// }
|
||||
|
||||
// const contactDonations = (await this.contactRepository.findOne({ id: contact.id }, { relations: ["donations"] })).donations;
|
||||
// if (contactDonations.length > 0 && !force) {
|
||||
// throw new DonorHasDonationsError();
|
||||
// }
|
||||
// const donationController = new DonationController();
|
||||
// for (let donation of contactDonations) {
|
||||
// await donationController.remove(donation.id, force);
|
||||
// }
|
||||
|
||||
// await this.contactRepository.delete(contact);
|
||||
// return new ResponseDonor(responseDonor);
|
||||
// }
|
||||
await this.contactRepository.delete(contact);
|
||||
return responseContact.toResponse();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user