Skip to content

Commit daa879e

Browse files
wes-cuttingWesHMCarsonF
authored
Migrate remaining enums to makeEnum (#2904)
Co-authored-by: Wes Cutting <[email protected]> Co-authored-by: Carson Full <[email protected]>
1 parent 866dde4 commit daa879e

File tree

92 files changed

+716
-758
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+716
-758
lines changed

src/common/sensitivity.enum.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import { applyDecorators } from '@nestjs/common';
2-
import { Field, FieldOptions, registerEnumType } from '@nestjs/graphql';
2+
import { Field, FieldOptions } from '@nestjs/graphql';
33
import { Transform } from 'class-transformer';
44
import { uniq } from 'lodash';
55
import { rankSens } from '../core/database/query';
66
import { DbSort } from './db-sort.decorator';
7+
import { EnumType, makeEnum } from './make-enum';
78

8-
export enum Sensitivity {
9-
Low = 'Low',
10-
Medium = 'Medium',
11-
High = 'High',
12-
}
13-
14-
registerEnumType(Sensitivity, {
9+
export type Sensitivity = EnumType<typeof Sensitivity>;
10+
export const Sensitivity = makeEnum({
1511
name: 'Sensitivity',
12+
values: ['Low', 'Medium', 'High'],
1613
});
1714

1815
export const SensitivityField = (options: FieldOptions = {}) =>

src/components/admin/admin.service.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
22
import { DateTime } from 'luxon';
3-
import { ID, ServerException } from '~/common';
3+
import { ID, Role, ServerException } from '~/common';
44
import { ConfigService } from '~/core/config/config.service';
55
import { Transactional } from '~/core/database';
66
import { ILogger, Logger } from '~/core/logger';
77
import { AuthenticationService } from '../authentication';
88
import { CryptoService } from '../authentication/crypto.service';
9-
import { Powers, Role } from '../authorization/dto';
9+
import { Power } from '../authorization/dto';
1010
import { AdminRepository } from './admin.repository';
1111

1212
@Injectable()
@@ -84,8 +84,7 @@ export class AdminService implements OnApplicationBootstrap {
8484
});
8585

8686
// set root user label & give all powers
87-
const powers = Object.keys(Powers);
88-
await this.repo.setUserLabel(powers, id);
87+
await this.repo.setUserLabel([...Power.values], id);
8988
}
9089

9190
// TODO do this a different way. Using a global like this can cause race conditions.

src/components/authentication/login.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { stripIndent } from 'common-tags';
1010
import { AnonSession, GqlContextType, Session } from '../../common';
1111
import { Loader, LoaderOf } from '../../core';
12-
import { Powers as Power, Privileges } from '../authorization';
12+
import { Power, Privileges } from '../authorization';
1313
import { User, UserLoader } from '../user';
1414
import { AuthenticationService } from './authentication.service';
1515
import { LoginInput, LoginOutput, LogoutOutput } from './dto';

src/components/authentication/register.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { stripIndent } from 'common-tags';
1010
import { AnonSession, GqlContextType, Session } from '../../common';
1111
import { Loader, LoaderOf } from '../../core';
12-
import { Powers as Power, Privileges } from '../authorization';
12+
import { Power, Privileges } from '../authorization';
1313
import { User, UserLoader } from '../user';
1414
import { AuthenticationService } from './authentication.service';
1515
import { RegisterInput, RegisterOutput } from './dto';

src/components/authentication/session.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
UnauthenticatedException,
1414
} from '../../common';
1515
import { ConfigService, ILogger, Loader, LoaderOf, Logger } from '../../core';
16-
import { Powers as Power, Privileges } from '../authorization';
16+
import { Power, Privileges } from '../authorization';
1717
import { User, UserLoader } from '../user';
1818
import { AuthenticationService } from './authentication.service';
1919
import { SessionOutput } from './dto';

src/components/authorization/authorization.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Query, Resolver } from '@nestjs/graphql';
22
import { AnonSession, Session } from '~/common';
3-
import { Powers as Power } from './dto';
3+
import { Power } from './dto';
44
import { Privileges } from './policy';
55

66
@Resolver()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './role.dto';
2-
export * from './powers';
2+
export * from './power.enum';
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { EnumType, makeEnum } from '~/common';
2+
3+
export type Power = EnumType<typeof Power>;
4+
export const Power = makeEnum({
5+
name: 'Power',
6+
values: [
7+
'BetaFeatures',
8+
'CreateEthnoArt',
9+
'CreateFieldRegion',
10+
'CreateFieldZone',
11+
'CreateFilm',
12+
'CreateFundingAccount',
13+
'CreateLanguage',
14+
'CreateLiteracyMaterial',
15+
'CreateLocation',
16+
'CreateOrganization',
17+
'CreatePartner',
18+
'CreateProject',
19+
'CreateSong',
20+
'CreateStory',
21+
'CreateUser',
22+
{
23+
value: 'CreateBudget',
24+
deprecationReason: 'Use `Project.budget` instead',
25+
},
26+
{
27+
value: 'CreateBudgetRecord',
28+
deprecationReason: 'Use `Project.budget` instead',
29+
},
30+
{
31+
value: 'CreateCeremony',
32+
deprecationReason: 'Use `Engagement.ceremony` instead',
33+
},
34+
{
35+
value: 'CreateChangeRequest',
36+
deprecationReason: 'Use `Project.changeRequests` instead',
37+
},
38+
{
39+
value: 'CreateDirectory',
40+
deprecationReason: 'Use something else instead',
41+
},
42+
{
43+
value: 'CreateEducation',
44+
deprecationReason: 'Use `User.education` instead',
45+
},
46+
{
47+
value: 'CreateEthnologueLanguage',
48+
deprecationReason:
49+
'Just check `CreateLanguage` instead. This is a sub-object ',
50+
},
51+
{ value: 'CreateFile', deprecationReason: 'Use something else instead' },
52+
{
53+
value: 'CreateFileVersion',
54+
deprecationReason: 'Use something else instead',
55+
},
56+
{
57+
value: 'CreateInternshipEngagement',
58+
deprecationReason: 'Use `Project.engagements` instead',
59+
},
60+
{
61+
value: 'CreateLanguageEngagement',
62+
deprecationReason: 'Use `Project.engagements` instead',
63+
},
64+
{
65+
value: 'CreatePartnership',
66+
deprecationReason: 'Use `Project.partnerships` instead ',
67+
},
68+
{ value: 'CreatePost', deprecationReason: 'Use `X.posts` instead' },
69+
{
70+
value: 'CreateProduct',
71+
deprecationReason: 'Use `Engagement.products` instead',
72+
},
73+
{
74+
value: 'CreateProjectEngagement',
75+
deprecationReason: 'Use `Project.engagements` instead',
76+
},
77+
{
78+
value: 'CreateProjectMember',
79+
deprecationReason: 'Use `Project.team` instead',
80+
},
81+
{
82+
value: 'CreateTranslationEngagement',
83+
deprecationReason: 'Use `Project.engagements` instead',
84+
},
85+
{
86+
value: 'CreateUnavailability',
87+
deprecationReason: 'Use `User.unavailabilities` instead',
88+
},
89+
{
90+
value: 'GrantInternRole',
91+
deprecationReason: 'Use `AuthorizedRoles.Intern` instead',
92+
},
93+
{
94+
value: 'GrantLiaisonRole',
95+
deprecationReason: 'Use `AuthorizedRoles.Liaison` instead',
96+
},
97+
{
98+
value: 'GrantMentorRole',
99+
deprecationReason: 'Use `AuthorizedRoles.Mentor` instead',
100+
},
101+
{
102+
value: 'GrantRegionalCommunicationsCoordinatorRole',
103+
deprecationReason:
104+
'Use `AuthorizedRoles.RegionalCommunicationsCoordinator` instead',
105+
},
106+
{
107+
value: 'GrantTranslatorRole',
108+
deprecationReason: 'Use `AuthorizedRoles.Translator` instead',
109+
},
110+
],
111+
});

src/components/authorization/dto/powers.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/components/authorization/missing-power.exception.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { UnauthorizedException } from '../../common/exceptions';
2-
import { Powers } from './dto/powers';
1+
import { UnauthorizedException } from '~/common';
2+
import { Power } from './dto';
33

44
export class MissingPowerException extends UnauthorizedException {
55
constructor(
6-
readonly power: Powers,
6+
readonly power: Power,
77
message = `Missing required power: ${power}`,
88
previous?: Error,
99
) {

0 commit comments

Comments
 (0)