parent
4493c0e3d9
commit
1e9e24d99d
@ -1,6 +1,6 @@
|
|||||||
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
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 { GroupContactIdsNotMatchingError, GroupContactNotFoundError } from '../errors/GroupContactErrors';
|
||||||
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
||||||
import { CreateGroupContact } from '../models/actions/create/CreateGroupContact';
|
import { CreateGroupContact } from '../models/actions/create/CreateGroupContact';
|
||||||
@ -26,9 +26,16 @@ export class GroupContactController {
|
|||||||
@Authorized("CONTACT:GET")
|
@Authorized("CONTACT:GET")
|
||||||
@ResponseSchema(ResponseGroupContact, { isArray: true })
|
@ResponseSchema(ResponseGroupContact, { isArray: true })
|
||||||
@OpenAPI({ description: 'Lists all contacts. <br> This includes the contact\'s associated groups.' })
|
@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>();
|
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 => {
|
contacts.forEach(contact => {
|
||||||
responseContacts.push(contact.toResponse());
|
responseContacts.push(contact.toResponse());
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user