@@ -1,7 +1,9 @@
 | 
				
			|||||||
import { JsonController } from 'routing-controllers';
 | 
					import { Authorized, Get, JsonController, OnUndefined, Param } from 'routing-controllers';
 | 
				
			||||||
import { OpenAPI } 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 { GroupContact } from '../models/entities/GroupContact';
 | 
					import { GroupContact } from '../models/entities/GroupContact';
 | 
				
			||||||
 | 
					import { ResponseGroupContact } from '../models/responses/ResponseGroupContact';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@JsonController('/contacts')
 | 
					@JsonController('/contacts')
 | 
				
			||||||
@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
 | 
					@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
 | 
				
			||||||
@@ -15,30 +17,30 @@ export class ContactController {
 | 
				
			|||||||
		this.contactRepository = getConnectionManager().get().getRepository(GroupContact);
 | 
							this.contactRepository = getConnectionManager().get().getRepository(GroupContact);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// @Get()
 | 
						@Get()
 | 
				
			||||||
	// @Authorized("DONOR:GET")
 | 
						@Authorized("CONTACT:GET")
 | 
				
			||||||
	// @ResponseSchema(ResponseDonor, { isArray: true })
 | 
						@ResponseSchema(ResponseGroupContact, { isArray: true })
 | 
				
			||||||
	// @OpenAPI({ description: 'Lists all contact. <br> This includes the contact\'s current donation amount.' })
 | 
						@OpenAPI({ description: 'Lists all contacts. <br> This includes the contact\'s associated groups.' })
 | 
				
			||||||
	// async getAll() {
 | 
						async getAll() {
 | 
				
			||||||
	// 	let responseDonors: ResponseDonor[] = new Array<ResponseDonor>();
 | 
							let responseContacts: ResponseGroupContact[] = new Array<ResponseGroupContact>();
 | 
				
			||||||
	// 	const contacts = await this.contactRepository.find({ relations: ['donations', 'donations.runner', 'donations.runner.scans', 'donations.runner.scans.track'] });
 | 
							const contacts = await this.contactRepository.find({ relations: ['groups'] });
 | 
				
			||||||
	// 	contacts.forEach(contact => {
 | 
							contacts.forEach(contact => {
 | 
				
			||||||
	// 		responseDonors.push(new ResponseDonor(contact));
 | 
								responseContacts.push(contact.toResponse());
 | 
				
			||||||
	// 	});
 | 
							});
 | 
				
			||||||
	// 	return responseDonors;
 | 
							return responseContacts;
 | 
				
			||||||
	// }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// @Get('/:id')
 | 
						@Get('/:id')
 | 
				
			||||||
	// @Authorized("DONOR:GET")
 | 
						@Authorized("DONOR:GET")
 | 
				
			||||||
	// @ResponseSchema(ResponseDonor)
 | 
						@ResponseSchema(ResponseGroupContact)
 | 
				
			||||||
	// @ResponseSchema(DonorNotFoundError, { statusCode: 404 })
 | 
						@ResponseSchema(GroupContactNotFoundError, { statusCode: 404 })
 | 
				
			||||||
	// @OnUndefined(DonorNotFoundError)
 | 
						@OnUndefined(GroupContactNotFoundError)
 | 
				
			||||||
	// @OpenAPI({ description: 'Lists all information about the contact whose id got provided. <br> This includes the contact\'s current donation amount.' })
 | 
						@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) {
 | 
						async getOne(@Param('id') id: number) {
 | 
				
			||||||
	// 	let contact = await this.contactRepository.findOne({ id: id }, { relations: ['donations', 'donations.runner', 'donations.runner.scans', 'donations.runner.scans.track'] })
 | 
							let contact = await this.contactRepository.findOne({ id: id }, { relations: ['groups'] })
 | 
				
			||||||
	// 	if (!contact) { throw new DonorNotFoundError(); }
 | 
							if (!contact) { throw new GroupContactNotFoundError(); }
 | 
				
			||||||
	// 	return new ResponseDonor(contact);
 | 
							return contact.toResponse();
 | 
				
			||||||
	// }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// @Post()
 | 
						// @Post()
 | 
				
			||||||
	// @Authorized("DONOR:CREATE")
 | 
						// @Authorized("DONOR:CREATE")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user