Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0573 Location.defaultMarketingRegion #2987

Merged
merged 8 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/location/dto/create-location.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Field, InputType, ObjectType } from '@nestjs/graphql';
import { Type } from 'class-transformer';
import { ValidateNested } from 'class-validator';
import { ID, IdField, ISO31661Alpha3, NameField } from '../../../common';
import { ID, IdField, IdOf, ISO31661Alpha3, NameField } from '../../../common';
import { Transform } from '../../../common/transform.decorator';
import { CreateDefinedFileVersionInput } from '../../file/dto';
import { LocationType } from './location-type.enum';
Expand Down Expand Up @@ -29,6 +29,9 @@ export abstract class CreateLocation {
@IdField({ nullable: true })
readonly defaultFieldRegionId?: ID;

@IdField({ nullable: true })
readonly marketingRegionId?: IdOf<Location>;

@Field({ nullable: true })
@Type(() => CreateDefinedFileVersionInput)
@ValidateNested()
Expand Down
3 changes: 3 additions & 0 deletions src/components/location/dto/location.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DbLabel,
DbUnique,
ID,
IdOf,
NameField,
Resource,
Secured,
Expand Down Expand Up @@ -47,6 +48,8 @@ export class Location extends Resource {

readonly defaultFieldRegion: Secured<ID | null>;

readonly marketingRegion: Secured<IdOf<Location> | null>;

readonly mapImage: DefinedFile;
}

Expand Down
5 changes: 4 additions & 1 deletion src/components/location/dto/update-location.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Field, InputType, ObjectType } from '@nestjs/graphql';
import { Type } from 'class-transformer';
import { ValidateNested } from 'class-validator';
import { ID, IdField, ISO31661Alpha3, NameField } from '../../../common';
import { ID, IdField, IdOf, ISO31661Alpha3, NameField } from '../../../common';
import { Transform } from '../../../common/transform.decorator';
import { CreateDefinedFileVersionInput } from '../../file/dto';
import { LocationType } from './location-type.enum';
Expand Down Expand Up @@ -32,6 +32,9 @@ export abstract class UpdateLocation {
@IdField({ nullable: true })
readonly defaultFieldRegionId?: ID | null;

@IdField({ nullable: true })
readonly marketingRegionId?: IdOf<Location>;

@Field({ nullable: true })
@Type(() => CreateDefinedFileVersionInput)
@ValidateNested()
Expand Down
17 changes: 17 additions & 0 deletions src/components/location/location.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class LocationRepository extends DtoRepository(Location) {
createRelationships(Location, 'out', {
fundingAccount: ['FundingAccount', input.fundingAccountId],
defaultFieldRegion: ['FieldRegion', input.defaultFieldRegionId],
marketingRegion: ['Location', input.marketingRegionId],
}),
)
.return<{ id: ID }>('node.id as id');
Expand All @@ -74,6 +75,7 @@ export class LocationRepository extends DtoRepository(Location) {
id,
fundingAccountId,
defaultFieldRegionId,
marketingRegionId,
mapImage,
...simpleChanges
} = changes;
Expand All @@ -97,6 +99,15 @@ export class LocationRepository extends DtoRepository(Location) {
defaultFieldRegionId,
);
}

if (marketingRegionId !== undefined) {
await this.updateRelation(
'marketingRegion',
'marketingRegion',
willdch marked this conversation as resolved.
Show resolved Hide resolved
id,
marketingRegionId,
);
}
}

protected hydrate() {
Expand All @@ -113,10 +124,16 @@ export class LocationRepository extends DtoRepository(Location) {
relation('out', '', 'defaultFieldRegion', ACTIVE),
node('defaultFieldRegion', 'FieldRegion'),
])
.optionalMatch([
node('node'),
relation('out', '', 'marketingRegion', ACTIVE),
node('marketingRegion', 'marketingRegion'),
willdch marked this conversation as resolved.
Show resolved Hide resolved
])
.return<{ dto: UnsecuredDto<Location> }>(
merge('props', {
fundingAccount: 'fundingAccount.id',
defaultFieldRegion: 'defaultFieldRegion.id',
marketingRegion: 'marketingRegion.id',
}).as('dto'),
);
}
Expand Down
8 changes: 8 additions & 0 deletions test/utility/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ export const org = gql`
}
}
}
marketingRegion {
value {
id
name {
value
}
}
}
}
}
}
Expand Down
Loading