|
|
|
|
@@ -28,7 +28,7 @@ export class GroupContactController {
|
|
|
|
|
@OpenAPI({ description: 'Lists all contacts. <br> This includes the contact\'s associated groups.' })
|
|
|
|
|
async getAll() {
|
|
|
|
|
let responseContacts: ResponseGroupContact[] = new Array<ResponseGroupContact>();
|
|
|
|
|
const contacts = await this.contactRepository.find({ relations: ['groups'] });
|
|
|
|
|
const contacts = await this.contactRepository.find({ relations: ['groups', 'groups.parentGroup'] });
|
|
|
|
|
contacts.forEach(contact => {
|
|
|
|
|
responseContacts.push(contact.toResponse());
|
|
|
|
|
});
|
|
|
|
|
@@ -42,7 +42,7 @@ export class GroupContactController {
|
|
|
|
|
@OnUndefined(GroupContactNotFoundError)
|
|
|
|
|
@OpenAPI({ description: 'Lists all information about the contact whose id got provided. <br> This includes the contact\'s associated groups.' })
|
|
|
|
|
async getOne(@Param('id') id: number) {
|
|
|
|
|
let contact = await this.contactRepository.findOne({ id: id }, { relations: ['groups'] })
|
|
|
|
|
let contact = await this.contactRepository.findOne({ id: id }, { relations: ['groups', 'groups.parentGroup'] })
|
|
|
|
|
if (!contact) { throw new GroupContactNotFoundError(); }
|
|
|
|
|
return contact.toResponse();
|
|
|
|
|
}
|
|
|
|
|
@@ -61,7 +61,7 @@ export class GroupContactController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contact = await this.contactRepository.save(contact)
|
|
|
|
|
return (await this.contactRepository.findOne({ id: contact.id }, { relations: ['groups'] })).toResponse();
|
|
|
|
|
return (await this.contactRepository.findOne({ id: contact.id }, { relations: ['groups', 'groups.parentGroup'] })).toResponse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put('/:id')
|
|
|
|
|
@@ -83,7 +83,7 @@ export class GroupContactController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.contactRepository.save(await contact.update(oldContact));
|
|
|
|
|
return (await this.contactRepository.findOne({ id: contact.id }, { relations: ['groups'] })).toResponse();
|
|
|
|
|
return (await this.contactRepository.findOne({ id: contact.id }, { relations: ['groups', 'groups.parentGroup'] })).toResponse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete('/:id')
|
|
|
|
|
@@ -95,7 +95,7 @@ export class GroupContactController {
|
|
|
|
|
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'] });
|
|
|
|
|
const responseContact = await this.contactRepository.findOne(contact, { relations: ['groups', 'groups.parentGroup'] });
|
|
|
|
|
for (let group of responseContact.groups) {
|
|
|
|
|
group.contact = null;
|
|
|
|
|
await getConnection().getRepository(RunnerGroup).save(group);
|
|
|
|
|
|