Skip to content

Commit a288608

Browse files
committed
add fields to Partner
1 parent 8bc61f7 commit a288608

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
@@ -97,6 +97,8 @@ export class PartnerRepository extends DtoRepository<
9797
fieldRegions: ['FieldRegion', input.fieldRegions],
9898
countries: ['Location', input.countries],
9999
languagesOfConsulting: ['Language', input.languagesOfConsulting],
100+
strategicAlliances: ['Partner', input.strategicAlliances],
101+
parent: ['Partner', input.parentId],
100102
}),
101103
)
102104
.apply(departmentIdBlockUtils.createMaybe(input.departmentIdBlock))
@@ -122,11 +124,17 @@ export class PartnerRepository extends DtoRepository<
122124
countries,
123125
languagesOfConsulting,
124126
departmentIdBlock,
127+
strategicAlliances,
128+
parentId,
125129
...simpleChanges
126130
} = changes;
127131

128132
await this.updateProperties({ id }, simpleChanges);
129133

134+
if (parentId !== undefined) {
135+
await this.updateRelation('parent', 'Partner', changes.id, parentId);
136+
}
137+
130138
if (pointOfContactId !== undefined) {
131139
await this.updateRelation(
132140
'pointOfContact',
@@ -173,6 +181,20 @@ export class PartnerRepository extends DtoRepository<
173181
}
174182
}
175183

184+
if (strategicAlliances) {
185+
try {
186+
await this.updateRelationList({
187+
id: changes.id,
188+
relation: 'strategicAlliances',
189+
newList: strategicAlliances,
190+
});
191+
} catch (e) {
192+
throw e instanceof InputException
193+
? e.withField('partner.strategicAlliances')
194+
: e;
195+
}
196+
}
197+
176198
if (languagesOfConsulting) {
177199
try {
178200
await this.updateRelationList({
@@ -261,6 +283,26 @@ export class PartnerRepository extends DtoRepository<
261283
),
262284
),
263285
)
286+
.subQuery('node', (sub) =>
287+
sub
288+
.match([
289+
node('node'),
290+
relation('out', '', 'strategicAlliances'),
291+
node('strategicAlliances', 'Partner'),
292+
])
293+
.return(
294+
collect('strategicAlliances { .id }').as('strategicAlliances'),
295+
),
296+
)
297+
.subQuery('node', (sub) =>
298+
sub
299+
.optionalMatch([
300+
node('node'),
301+
relation('out', '', 'parent', ACTIVE),
302+
node('parent', 'Partner'),
303+
])
304+
.return('parent { .id } as parent'),
305+
)
264306
.apply(matchProps())
265307
.optionalMatch([
266308
node('node'),
@@ -292,6 +334,8 @@ export class PartnerRepository extends DtoRepository<
292334
departmentIdBlock: 'departmentIdBlock',
293335
scope: 'scopedRoles',
294336
pinned: 'exists((:User { id: $requestingUser })-[:pinned]->(node))',
337+
parent: 'parent { .id }',
338+
strategicAlliances: 'strategicAlliances',
295339
}).as('dto'),
296340
);
297341
}

src/components/partner/partner.resolver.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import {
4545
Partner,
4646
PartnerListInput,
4747
PartnerListOutput,
48+
SecuredPartner,
49+
SecuredPartners,
4850
UpdatePartnerInput,
4951
UpdatePartnerOutput,
5052
} from './dto';
@@ -63,6 +65,25 @@ export class PartnerResolver {
6365
return await partners.load(id);
6466
}
6567

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

0 commit comments

Comments
 (0)