parent
4493c0e3d9
commit
1e9e24d99d
|
@ -1,6 +1,6 @@
|
|||
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnection, getConnectionManager, Repository } from 'typeorm';
|
||||
import { Repository, getConnection, getConnectionManager } from 'typeorm';
|
||||
import { GroupContactIdsNotMatchingError, GroupContactNotFoundError } from '../errors/GroupContactErrors';
|
||||
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
||||
import { CreateGroupContact } from '../models/actions/create/CreateGroupContact';
|
||||
|
@ -26,9 +26,16 @@ export class GroupContactController {
|
|||
@Authorized("CONTACT:GET")
|
||||
@ResponseSchema(ResponseGroupContact, { isArray: true })
|
||||
@OpenAPI({ description: 'Lists all contacts. <br> This includes the contact\'s associated groups.' })
|
||||
async getAll() {
|
||||
async getAll(@QueryParam("page", { required: false }) page: number, @QueryParam("page_size", { required: false }) page_size: number = 100) {
|
||||
let responseContacts: ResponseGroupContact[] = new Array<ResponseGroupContact>();
|
||||
const contacts = await this.contactRepository.find({ relations: ['groups', 'groups.parentGroup'] });
|
||||
let contacts: Array<GroupContact>;
|
||||
|
||||
if (page) {
|
||||
contacts = await this.contactRepository.find({ relations: ['groups', 'groups.parentGroup'], skip: page * page_size, take: page_size });
|
||||
} else {
|
||||
contacts = await this.contactRepository.find({ relations: ['groups', 'groups.parentGroup'] });
|
||||
}
|
||||
|
||||
contacts.forEach(contact => {
|
||||
responseContacts.push(contact.toResponse());
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue