Skip to content

Commit

Permalink
Merge pull request #3283 from SeedCompany/engagement-refactor
Browse files Browse the repository at this point in the history
Refactor Engagement module / Prep for EdgeDB
  • Loading branch information
CarsonF authored Sep 4, 2024
2 parents 581f9b6 + 0580dd6 commit c54e329
Show file tree
Hide file tree
Showing 13 changed files with 298 additions and 344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class CreateEngagementDefaultCeremonyHandler

event.engagement = {
...engagement,
ceremony: ceremonyId,
ceremony: { id: ceremonyId },
};
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { EventsHandler, IEventHandler } from '~/core';
import { ConfigService, EventsHandler, IEventHandler } from '~/core';
import { EngagementWillDeleteEvent } from '../../engagement/events';
import { CeremonyService } from '../ceremony.service';

@EventsHandler(EngagementWillDeleteEvent)
export class DetachEngagementRootDirectoryHandler
implements IEventHandler<EngagementWillDeleteEvent>
{
constructor(private readonly ceremonies: CeremonyService) {}
constructor(
private readonly ceremonies: CeremonyService,
private readonly config: ConfigService,
) {}

async handle({ engagement, session }: EngagementWillDeleteEvent) {
const ceremonyId = engagement?.ceremony?.value;
if (this.config.databaseEngine === 'edgedb') {
return;
}

const ceremonyId = engagement?.ceremony?.value?.id;
if (!ceremonyId) {
return;
}
Expand Down
35 changes: 14 additions & 21 deletions src/components/engagement/dto/engagement.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@ import {
DateInterval,
DateTimeField,
DbLabel,
ID,
IntersectTypes,
parentIdMiddleware,
Resource,
ResourceRelationsShape,
Secured,
SecuredBoolean,
SecuredDateNullable,
SecuredDateTime,
SecuredDateTimeNullable,
SecuredProps,
SecuredRichTextNullable,
SecuredString,
SecuredStringNullable,
Sensitivity,
SensitivityField,
UnsecuredDto,
} from '~/common';
import { BaseNode } from '~/core/database/results';
import { e } from '~/core/edgedb';
import { LinkTo, RegisterResource } from '~/core/resources';
import { ScopedRole } from '../../authorization/dto';
import { ChangesetAware } from '../../changeset/dto';
import { DefinedFile } from '../../file/dto';
import { Product, SecuredMethodologies } from '../../product/dto';
import {
InternshipProject,
Expand Down Expand Up @@ -80,7 +77,7 @@ class Engagement extends Interfaces {
@DbLabel('EngagementStatus')
readonly status: SecuredEngagementStatus;

readonly ceremony: Secured<ID>;
readonly ceremony: Secured<LinkTo<'Ceremony'>>;

@Field({
description: 'Translation / Growth Plan complete date',
Expand Down Expand Up @@ -119,25 +116,21 @@ class Engagement extends Interfaces {

@Field()
// Convert from date to datetime at migration
readonly lastSuspendedAt: SecuredDateTime;
readonly lastSuspendedAt: SecuredDateTimeNullable;

@Field()
// Convert from date to datetime at migration
readonly lastReactivatedAt: SecuredDateTime;
readonly lastReactivatedAt: SecuredDateTimeNullable;

@Field({
description: 'The last time the engagement status was modified',
})
// Convert from last terminated/completed at migration
readonly statusModifiedAt: SecuredDateTime;
readonly statusModifiedAt: SecuredDateTimeNullable;

@DateTimeField()
readonly modifiedAt: DateTime;

// A list of non-global roles the requesting user has available for this object.
// This is just a cache, to prevent extra db lookups within the same request.
declare readonly scope: ScopedRole[];

@Field()
readonly description: SecuredRichTextNullable;
}
Expand Down Expand Up @@ -166,7 +159,7 @@ export class LanguageEngagement extends Engagement {
@Field(() => TranslationProject)
declare readonly parent: BaseNode;

readonly language: Secured<ID>;
readonly language: Secured<LinkTo<'Language'>>;

@Field()
readonly firstScripture: SecuredBoolean;
Expand All @@ -183,12 +176,12 @@ export class LanguageEngagement extends Engagement {
readonly sentPrintingDate: SecuredDateNullable;

@Field()
readonly paratextRegistryId: SecuredString;
readonly paratextRegistryId: SecuredStringNullable;

readonly pnp: DefinedFile;
readonly pnp: Secured<LinkTo<'File'> | null>;

@Field()
readonly historicGoal: SecuredString;
readonly historicGoal: SecuredStringNullable;
}

@RegisterResource({ db: e.InternshipEngagement })
Expand All @@ -207,11 +200,11 @@ export class InternshipEngagement extends Engagement {
@Field(() => InternshipProject)
declare readonly parent: BaseNode;

readonly countryOfOrigin: Secured<ID | null>;
readonly countryOfOrigin: Secured<LinkTo<'Location'> | null>;

readonly intern: Secured<ID>;
readonly intern: Secured<LinkTo<'User'>>;

readonly mentor: Secured<ID | null>;
readonly mentor: Secured<LinkTo<'User'> | null>;

@Field()
@DbLabel('InternPosition')
Expand All @@ -221,7 +214,7 @@ export class InternshipEngagement extends Engagement {
@DbLabel('ProductMethodology')
readonly methodologies: SecuredMethodologies;

readonly growthPlan: DefinedFile;
readonly growthPlan: Secured<LinkTo<'File'> | null>;
}

export const engagementRange = (engagement: UnsecuredDto<Engagement>) =>
Expand Down
Loading

0 comments on commit c54e329

Please sign in to comment.