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

[EdgeDB] Add Engagement queries | refactor service/repo layers appropriately #3219

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
15 changes: 14 additions & 1 deletion dbschema/engagement.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@ module default {
property firstScripture := (
exists .language.firstScriptureEngagement
);


trigger denyDuplicateFirstScriptureBasedOnExternal after insert, update for each do (
assert(
not __new__.firstScripture or not exists __new__.language.hasExternalFirstScripture,
message := "First scripture has already been marked as having been done externally"
)
);
trigger denyDuplicateFirstScriptureBasedOnOtherEngagement after insert, update for each do (
assert(
not exists (select __new__.language.engagements filter .firstScripture),
message := "Another engagement has already been marked as having done the first scripture"
)
);

required lukePartnership: bool {
default := false;
};
Expand Down
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,16 +1,19 @@
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 (!ceremonyId) {
const ceremony = engagement?.ceremony?.value;
if (!ceremony) {
return;
}

Expand All @@ -19,6 +22,10 @@ export class DetachEngagementRootDirectoryHandler
return;
}

await this.ceremonies.delete(ceremonyId, session);
if (this.config.databaseEngine === 'edgedb') {
return;
}

await this.ceremonies.delete(ceremony.id, session);
}
}
40 changes: 19 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,12 +214,17 @@ 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>) =>
DateInterval.tryFrom(engagement.startDate, engagement.endDate);

export const EngagementConcretes = {
LanguageEngagement: LanguageEngagement,
InternshipEngagement: InternshipEngagement,
} as const satisfies Record<Engagement['__typename'], typeof Engagement>;

declare module '~/core/resources/map' {
interface ResourceMap {
Engagement: typeof Engagement;
Expand Down
Loading
Loading