Skip to content

Commit 8064521

Browse files
bryanjnelsonCarsonF
authored andcommitted
Add Organization.type
1 parent f746ade commit 8064521

File tree

7 files changed

+50
-1
lines changed

7 files changed

+50
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Field, InputType, ObjectType } from '@nestjs/graphql';
22
import { Type } from 'class-transformer';
33
import { ValidateNested } from 'class-validator';
44
import { NameField } from '../../../common';
5+
import { OrganizationType } from './organization-type.dto';
56
import { Organization } from './organization.dto';
67

78
@InputType()
@@ -14,6 +15,9 @@ export abstract class CreateOrganization {
1415

1516
@Field({ nullable: true })
1617
readonly address?: string;
18+
19+
@Field(() => [OrganizationType], { nullable: true })
20+
readonly types?: readonly OrganizationType[];
1721
}
1822

1923
@InputType()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ObjectType } from '@nestjs/graphql';
2+
import { EnumType, makeEnum, SecuredEnumList } from '~/common';
3+
4+
/**
5+
* The type of organization.
6+
*/
7+
export type OrganizationType = EnumType<typeof OrganizationType>;
8+
export const OrganizationType = makeEnum({
9+
name: 'OrganizationType',
10+
description: 'The type of organization',
11+
values: [
12+
'Church',
13+
'Parachurch',
14+
'Mission',
15+
'TranslationOrganization',
16+
'Alliance',
17+
],
18+
});
19+
20+
@ObjectType({
21+
description: SecuredEnumList.descriptionFor('organization types'),
22+
})
23+
export class SecuredOrganizationTypes extends SecuredEnumList(
24+
OrganizationType,
25+
) {}

src/components/organization/dto/organization.dto.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
SensitivityField,
1515
} from '../../../common';
1616
import { Location } from '../../location/dto';
17+
import { SecuredOrganizationTypes } from './organization-type.dto';
1718

1819
@RegisterResource()
1920
@ObjectType({
@@ -41,6 +42,9 @@ export class Organization extends Resource {
4142
"Based on the projects' lowest sensitivity, and defaults to 'High' if no project is connected",
4243
})
4344
readonly sensitivity: Sensitivity;
45+
46+
@Field()
47+
readonly types: SecuredOrganizationTypes;
4448
}
4549

4650
@ObjectType({

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Field, InputType, ObjectType } from '@nestjs/graphql';
22
import { Type } from 'class-transformer';
33
import { ValidateNested } from 'class-validator';
44
import { ID, IdField, NameField } from '../../../common';
5+
import { OrganizationType } from './organization-type.dto';
56
import { Organization } from './organization.dto';
67

78
@InputType()
@@ -17,6 +18,9 @@ export abstract class UpdateOrganization {
1718

1819
@Field({ nullable: true })
1920
readonly address?: string;
21+
22+
@Field(() => [OrganizationType], { nullable: true })
23+
readonly types?: readonly OrganizationType[];
2024
}
2125

2226
@InputType()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { BaseMigration, Migration } from '~/core';
2+
import { Organization } from '../dto';
3+
4+
@Migration('2023-08-04T00:00:00')
5+
export class AddOrganizationTypeMigration extends BaseMigration {
6+
async up() {
7+
await this.addProperty(Organization, 'types', []);
8+
}
9+
}

src/components/organization/organization.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { forwardRef, Module } from '@nestjs/common';
22
import { AuthorizationModule } from '../authorization/authorization.module';
33
import { LocationModule } from '../location/location.module';
4+
import { AddOrganizationTypeMigration } from './migrations/add-type.migration';
45
import { OrganizationLoader } from './organization.loader';
56
import { OrganizationRepository } from './organization.repository';
67
import { OrganizationResolver } from './organization.resolver';
@@ -13,6 +14,7 @@ import { OrganizationService } from './organization.service';
1314
OrganizationService,
1415
OrganizationRepository,
1516
OrganizationLoader,
17+
AddOrganizationTypeMigration,
1618
],
1719
exports: [OrganizationService],
1820
})

src/components/organization/organization.repository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ export class OrganizationRepository extends DtoRepository<
2626
async create(input: CreateOrganization, session: Session) {
2727
const initialProps = {
2828
name: input.name,
29-
address: input.address,
3029
acronym: input.acronym,
30+
address: input.address,
31+
types: input.types ?? [],
3132
canDelete: true,
3233
};
3334

0 commit comments

Comments
 (0)