Skip to content

Commit

Permalink
More EdgeDB Engagement work
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjnelson authored and CarsonF committed Aug 29, 2024
1 parent e600b88 commit d8bcf0f
Showing 1 changed file with 61 additions and 58 deletions.
119 changes: 61 additions & 58 deletions src/components/engagement/engagement.edgedb.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { Injectable, Type } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { LazyGetter } from 'lazy-get-decorator';
import { difference } from 'lodash';
import { ID, PublicOf, Session } from '~/common';
import {
ID,
NotImplementedException,
PublicOf,
Session,
UnsecuredDto,
} from '~/common';
import { grabInstances } from '~/common/instance-maps';
import { castToEnum, e, RepoFor } from '~/core/edgedb';
import { ProjectType } from '../project/dto';
Expand All @@ -12,6 +18,8 @@ import {
CreateLanguageEngagement,
EngagementStatus,
IEngagement,
InternshipEngagement,
LanguageEngagement,
UpdateInternshipEngagement,
UpdateLanguageEngagement,
} from './dto';
Expand Down Expand Up @@ -40,24 +48,24 @@ const baseHydrate = e.shape(e.Engagement, (engagement) => ({
completeDate: engagement.completedDate, // TODO fix in schema
}));

const languageExtraHydrate = e.shape(e.LanguageEngagement, (le) => ({
language: true,
firstScripture: true,
lukePartnership: true,
openToInvestorVisit: true,
sentPrintingDate: true,
paratextRegistryId: true,
pnp: true,
historicGoal: true,
const languageExtraHydrate = e.shape(e.LanguageEngagement, () => ({
...e.is(e.LanguageEngagement, { language: true }),
...e.is(e.LanguageEngagement, { firstScripture: true }),
...e.is(e.LanguageEngagement, { lukePartnership: true }),
...e.is(e.LanguageEngagement, { openToInvestorVisit: true }),
...e.is(e.LanguageEngagement, { sentPrintingDate: true }),
...e.is(e.LanguageEngagement, { paratextRegistryId: true }),
...e.is(e.LanguageEngagement, { pnp: true }),
...e.is(e.LanguageEngagement, { historicGoal: true }),
}));

const internshipExtraHydrate = e.shape(e.InternshipEngagement, (ie) => ({
countryOfOrigin: true,
intern: true,
mentor: true,
position: true,
methodologies: true,
growthPlan: true,
const internshipExtraHydrate = e.shape(e.InternshipEngagement, () => ({
...e.is(e.InternshipEngagement, { countryOfOrigin: true }),
...e.is(e.InternshipEngagement, { intern: true }),
...e.is(e.InternshipEngagement, { mentor: true }),
...e.is(e.InternshipEngagement, { position: true }),
...e.is(e.InternshipEngagement, { methodologies: true }),
...e.is(e.InternshipEngagement, { growthPlan: true }),
}));

const languageHydrate = e.shape(e.LanguageEngagement, (le) => ({
Expand All @@ -78,8 +86,8 @@ const internshipHydrate = e.shape(e.InternshipEngagement, (ie) => ({

const hydrate = e.shape(e.Engagement, (engagement) => ({
...baseHydrate(engagement),
...languageExtraHydrate(engagement),
...internshipExtraHydrate(engagement),
...languageHydrate(engagement),
...internshipHydrate(engagement),
}));

export const ConcreteRepos = {
Expand All @@ -102,8 +110,20 @@ export const ConcreteRepos = {

InternshipEngagement: class InternshipEngagementRepository extends RepoFor(
ConcreteTypes.InternshipEngagement,
{ hydrate: internshipHydrate },
) {},
{ hydrate: internshipHydrate, omit: ['create', 'update'] },
) {
async create(input: CreateInternshipEngagement) {
const project = e.cast(e.InternshipProject, e.uuid(input.projectId));
return await this.defaults.create({
...input,
projectContext: project.projectContext,
});
}

async update({ id, ...changes }: UpdateInternshipEngagement) {
return await this.defaults.update({ id, ...changes });
}
},
} satisfies Record<keyof typeof ConcreteTypes, Type>;

@Injectable()
Expand Down Expand Up @@ -139,53 +159,36 @@ export class EngagementEdgeDBRepository
return this.concretes.LanguageEngagement.getActualChanges;
}

async updateLanguage(input: UpdateLanguageEngagement) {
return await this.concretes.LanguageEngagement.update(input);
}

get getActualInternshipChanges() {
return this.concretes.InternshipEngagement.getActualChanges;
}

async updateLanguage(input: UpdateLanguageEngagement) {

Check failure on line 166 in src/components/engagement/engagement.edgedb.repository.ts

View workflow job for this annotation

GitHub Actions / lint

Property 'updateLanguage' in type 'EngagementEdgeDBRepository' is not assignable to the same property in base type 'PublicOf<EngagementRepository>'.
return await this.concretes.LanguageEngagement.update(input);
}

async updateInternship(

Check failure on line 170 in src/components/engagement/engagement.edgedb.repository.ts

View workflow job for this annotation

GitHub Actions / lint

Property 'updateInternship' in type 'EngagementEdgeDBRepository' is not assignable to the same property in base type 'PublicOf<EngagementRepository>'.
changes: UpdateInternshipEngagement,
input: UpdateInternshipEngagement,
_session: Session,
_changeset?: ID,
) {
const { id, mentorId, countryOfOriginId, growthPlan, ...simpleChanges } =
changes;

const internshipEngagement = e.cast(e.InternshipEngagement, e.uuid(id));
const mentor = mentorId ? e.cast(e.User, e.uuid(mentorId)) : e.set();
const countryOfOrigin = countryOfOriginId
? e.cast(e.Location, e.uuid(countryOfOriginId))
: e.set();

if (growthPlan) {
//TODO
}

const updated = e.update(internshipEngagement, () => ({
set: {
...simpleChanges,
mentor,
countryOfOrigin,
},
}));

const query = e.select(updated, internshipHydrate);

return await this.db.run(query);
return await this.concretes.InternshipEngagement.update(input);
}

async listAllByProjectId(projectId: ID, _session: Session) {
const project = e.cast(e.Project, e.uuid(projectId));
const query = e.select(e.Engagement, (eng) => ({
filter: e.op(eng.project, '=', project),
...hydrate(eng),
}));

return await this.db.run(query);
async listAllByProjectId(
projectId: ID,
_session: Session,
): Promise<
ReadonlyArray<UnsecuredDto<LanguageEngagement | InternshipEngagement>>
> {
throw new NotImplementedException().with(projectId);
// const project = e.cast(e.Project, e.uuid(projectId));
// const query = e.select(e.Engagement, (eng) => ({
// filter: e.op(eng.project, '=', project),
// ...hydrate(eng),
// }));

// return await this.db.run(query);
}

async getOngoingEngagementIds(
Expand Down

0 comments on commit d8bcf0f

Please sign in to comment.