Skip to content

Commit 251e29e

Browse files
committed
add fields to Partner
1 parent 24aa0cd commit 251e29e

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

src/components/partner/dto/create-partner.dto.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ export abstract class CreatePartner {
5050
@IdField({ nullable: true })
5151
readonly languageOfWiderCommunicationId?: ID<'Language'> | null;
5252

53+
@IdField({ nullable: true })
54+
readonly parentId?: ID<'Partner'> | null;
55+
56+
@Field(() => [IDType], { nullable: true })
57+
@IsId({ each: true })
58+
@Transform(({ value }) => uniq(value))
59+
readonly strategicAlliances?: ReadonlyArray<ID<'Partner'>> = [];
60+
5361
@Field(() => [IDType], { nullable: true })
5462
@IsId({ each: true })
5563
@Transform(({ value }) => uniq(value))

src/components/partner/dto/partner.dto.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SecuredBoolean,
1010
SecuredDateNullable,
1111
SecuredProperty,
12+
SecuredPropertyList,
1213
SecuredStringNullable,
1314
Sensitivity,
1415
SensitivityField,
@@ -66,6 +67,9 @@ export class Partner extends Interfaces {
6667
>;
6768

6869
readonly countries: Required<Secured<ReadonlyArray<LinkTo<'Location'>>>>;
70+
readonly strategicAlliances: Required<
71+
Secured<ReadonlyArray<LinkTo<'Partner'>>>
72+
>;
6973

7074
readonly languagesOfConsulting: Required<
7175
Secured<ReadonlyArray<LinkTo<'Language'>>>
@@ -87,13 +91,20 @@ export class Partner extends Interfaces {
8791

8892
@Field()
8993
readonly departmentIdBlock: SecuredFinanceDepartmentIdBlockNullable;
94+
95+
readonly parent: Secured<LinkTo<'Partner'> | null>;
9096
}
9197

9298
@ObjectType({
9399
description: SecuredProperty.descriptionFor('a partner'),
94100
})
95101
export class SecuredPartner extends SecuredProperty(Partner) {}
96102

103+
@ObjectType({
104+
description: SecuredPropertyList.descriptionFor('a list of partners'),
105+
})
106+
export class SecuredPartners extends SecuredPropertyList(Partner) {}
107+
97108
declare module '~/core/resources/map' {
98109
interface ResourceMap {
99110
Partner: typeof Partner;

src/components/partner/dto/update-partner.dto.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ export abstract class UpdatePartner {
4848
@IdField({ nullable: true })
4949
readonly languageOfWiderCommunicationId?: ID<'Language'> | null;
5050

51+
@IdField({ nullable: true })
52+
readonly parentId?: ID<'Partner'> | null;
53+
54+
@ListField(() => IDType, { optional: true })
55+
@IsId({ each: true })
56+
readonly strategicAlliances?: ReadonlyArray<ID<'Partner'>>;
57+
5158
@ListField(() => IDType, { optional: true })
5259
@IsId({ each: true })
5360
readonly countries?: ReadonlyArray<ID<'Location'>>;

src/components/partner/partner.repository.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export class PartnerRepository extends DtoRepository(Partner) {
9393
fieldRegions: ['FieldRegion', input.fieldRegions],
9494
countries: ['Location', input.countries],
9595
languagesOfConsulting: ['Language', input.languagesOfConsulting],
96+
strategicAlliances: ['Partner', input.strategicAlliances],
97+
parent: ['Partner', input.parentId],
9698
}),
9799
)
98100
.apply(departmentIdBlockUtils.createMaybe(input.departmentIdBlock))
@@ -118,11 +120,17 @@ export class PartnerRepository extends DtoRepository(Partner) {
118120
countries,
119121
languagesOfConsulting,
120122
departmentIdBlock,
123+
strategicAlliances,
124+
parentId,
121125
...simpleChanges
122126
} = changes;
123127

124128
await this.updateProperties({ id }, simpleChanges);
125129

130+
if (parentId !== undefined) {
131+
await this.updateRelation('parent', 'Partner', changes.id, parentId);
132+
}
133+
126134
if (pointOfContactId !== undefined) {
127135
await this.updateRelation(
128136
'pointOfContact',
@@ -169,6 +177,20 @@ export class PartnerRepository extends DtoRepository(Partner) {
169177
}
170178
}
171179

180+
if (strategicAlliances) {
181+
try {
182+
await this.updateRelationList({
183+
id: changes.id,
184+
relation: 'strategicAlliances',
185+
newList: strategicAlliances,
186+
});
187+
} catch (e) {
188+
throw e instanceof InputException
189+
? e.withField('partner.strategicAlliances')
190+
: e;
191+
}
192+
}
193+
172194
if (languagesOfConsulting) {
173195
try {
174196
await this.updateRelationList({
@@ -257,6 +279,26 @@ export class PartnerRepository extends DtoRepository(Partner) {
257279
),
258280
),
259281
)
282+
.subQuery('node', (sub) =>
283+
sub
284+
.match([
285+
node('node'),
286+
relation('out', '', 'strategicAlliances'),
287+
node('strategicAlliances', 'Partner'),
288+
])
289+
.return(
290+
collect('strategicAlliances { .id }').as('strategicAlliances'),
291+
),
292+
)
293+
.subQuery('node', (sub) =>
294+
sub
295+
.optionalMatch([
296+
node('node'),
297+
relation('out', '', 'parent', ACTIVE),
298+
node('parent', 'Partner'),
299+
])
300+
.return('parent { .id } as parent'),
301+
)
260302
.apply(matchProps())
261303
.optionalMatch([
262304
node('node'),
@@ -288,6 +330,8 @@ export class PartnerRepository extends DtoRepository(Partner) {
288330
departmentIdBlock: 'departmentIdBlock',
289331
scope: 'scopedRoles',
290332
pinned,
333+
parent: 'parent { .id }',
334+
strategicAlliances: 'strategicAlliances',
291335
}).as('dto'),
292336
);
293337
}

src/components/partner/partner.resolver.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import {
4242
Partner,
4343
PartnerListInput,
4444
PartnerListOutput,
45+
SecuredPartner,
46+
SecuredPartners,
4547
UpdatePartnerInput,
4648
UpdatePartnerOutput,
4749
} from './dto';
@@ -60,6 +62,25 @@ export class PartnerResolver {
6062
return await partners.load(id);
6163
}
6264

65+
@ResolveField(() => SecuredPartner)
66+
async parent(
67+
@Parent() partner: Partner,
68+
@Loader(PartnerLoader) partners: LoaderOf<PartnerLoader>,
69+
): Promise<SecuredPartner> {
70+
return await mapSecuredValue(partner.parent, ({ id }) => partners.load(id));
71+
}
72+
73+
@ResolveField(() => SecuredPartners)
74+
async strategicAlliances(
75+
@Parent() partner: Partner,
76+
@Loader(PartnerLoader) loader: LoaderOf<PartnerLoader>,
77+
): Promise<SecuredPartners> {
78+
return await loadSecuredIds(loader, {
79+
...partner.strategicAlliances,
80+
value: partner.strategicAlliances.value?.map((alliance) => alliance.id),
81+
});
82+
}
83+
6384
@Query(() => PartnerListOutput, {
6485
description: 'Look up partners',
6586
})

0 commit comments

Comments
 (0)