Compare commits
No commits in common. "2eb26e4e381a97fd829a294501fa42ac7b712b56" and "de824375d3a1da6ee4d78ea39b7da66fc05f2a02" have entirely different histories.
2eb26e4e38
...
de824375d3
@ -1,10 +1,7 @@
|
|||||||
import { IsEmail, IsNotEmpty, IsObject, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
import { IsEmail, IsNotEmpty, IsObject, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
||||||
import { getConnectionManager } from 'typeorm';
|
|
||||||
import { config } from '../../../config';
|
import { config } from '../../../config';
|
||||||
import { RunnerGroupNotFoundError } from '../../../errors/RunnerGroupErrors';
|
|
||||||
import { Address } from '../../entities/Address';
|
import { Address } from '../../entities/Address';
|
||||||
import { GroupContact } from '../../entities/GroupContact';
|
import { GroupContact } from '../../entities/GroupContact';
|
||||||
import { RunnerGroup } from '../../entities/RunnerGroup';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This classed is used to create a new Group entity from a json body (post request).
|
* This classed is used to create a new Group entity from a json body (post request).
|
||||||
@ -53,30 +50,6 @@ export class CreateGroupContact {
|
|||||||
@IsEmail()
|
@IsEmail()
|
||||||
email?: string;
|
email?: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* The new contacts's groups' ids.
|
|
||||||
* You can provide either one groupId or an array of groupIDs.
|
|
||||||
*/
|
|
||||||
@IsOptional()
|
|
||||||
groups?: number[] | number
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get's all groups for this contact by their id's;
|
|
||||||
*/
|
|
||||||
public async getGroups(): Promise<RunnerGroup[]> {
|
|
||||||
if (!this.groups) { return null; }
|
|
||||||
let groups = new Array<RunnerGroup>();
|
|
||||||
if (!Array.isArray(this.groups)) {
|
|
||||||
this.groups = [this.groups]
|
|
||||||
}
|
|
||||||
for (let group of this.groups) {
|
|
||||||
let found = await getConnectionManager().get().getRepository(RunnerGroup).findOne({ id: group });
|
|
||||||
if (!found) { throw new RunnerGroupNotFoundError(); }
|
|
||||||
groups.push(found);
|
|
||||||
}
|
|
||||||
return groups;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Address entity from this.
|
* Creates a new Address entity from this.
|
||||||
@ -90,8 +63,6 @@ export class CreateGroupContact {
|
|||||||
newContact.phone = this.phone;
|
newContact.phone = this.phone;
|
||||||
newContact.address = this.address;
|
newContact.address = this.address;
|
||||||
Address.validate(newContact.address);
|
Address.validate(newContact.address);
|
||||||
newContact.groups = await this.getGroups();
|
|
||||||
|
|
||||||
return newContact;
|
return newContact;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -68,7 +68,6 @@ export class ResponseGroupContact {
|
|||||||
this.phone = contact.phone;
|
this.phone = contact.phone;
|
||||||
this.email = contact.email;
|
this.email = contact.email;
|
||||||
this.address = contact.address;
|
this.address = contact.address;
|
||||||
this.groups = new Array<ResponseRunnerGroup>();
|
|
||||||
for (let group of contact.groups) {
|
for (let group of contact.groups) {
|
||||||
this.groups.push(group.toResponse());
|
this.groups.push(group.toResponse());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user