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 { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { GroupContactNotFoundError } from '../errors/GroupContactErrors';
|
import { GroupContactNotFoundError } from '../errors/GroupContactErrors';
|
||||||
import { GroupContact } from '../models/entities/GroupContact';
|
import { GroupContact } from '../models/entities/GroupContact';
|
||||||
|
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
||||||
import { ResponseGroupContact } from '../models/responses/ResponseGroupContact';
|
import { ResponseGroupContact } from '../models/responses/ResponseGroupContact';
|
||||||
|
|
||||||
@JsonController('/contacts')
|
@JsonController('/contacts')
|
||||||
@ -31,7 +32,7 @@ export class ContactController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
@Authorized("DONOR:GET")
|
@Authorized("CONTACT:GET")
|
||||||
@ResponseSchema(ResponseGroupContact)
|
@ResponseSchema(ResponseGroupContact)
|
||||||
@ResponseSchema(GroupContactNotFoundError, { statusCode: 404 })
|
@ResponseSchema(GroupContactNotFoundError, { statusCode: 404 })
|
||||||
@OnUndefined(GroupContactNotFoundError)
|
@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'] }));
|
// return new ResponseDonor(await this.contactRepository.findOne({ id: id }, { relations: ['donations', 'donations.runner', 'donations.runner.scans', 'donations.runner.scans.track'] }));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// @Delete('/:id')
|
@Delete('/:id')
|
||||||
// @Authorized("DONOR:DELETE")
|
@Authorized("CONTACT:DELETE")
|
||||||
// @ResponseSchema(ResponseDonor)
|
@ResponseSchema(ResponseGroupContact)
|
||||||
// @ResponseSchema(ResponseEmpty, { statusCode: 204 })
|
@ResponseSchema(ResponseEmpty, { statusCode: 204 })
|
||||||
// @OnUndefined(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.' })
|
@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) {
|
async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
|
||||||
// let contact = await this.contactRepository.findOne({ id: id });
|
let contact = await this.contactRepository.findOne({ id: id });
|
||||||
// if (!contact) { return null; }
|
if (!contact) { return null; }
|
||||||
// const responseDonor = await this.contactRepository.findOne(contact, { relations: ['donations', 'donations.runner', 'donations.runner.scans', 'donations.runner.scans.track'] });
|
const responseContact = await this.contactRepository.findOne(contact, { relations: ['groups'] });
|
||||||
|
|
||||||
// if (!contact) {
|
await this.contactRepository.delete(contact);
|
||||||
// throw new DonorNotFoundError();
|
return responseContact.toResponse();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user