Skip to content

Commit

Permalink
EdgeDB repo method modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjnelson committed Jun 6, 2024
1 parent c77c4de commit 09d7db7
Showing 1 changed file with 87 additions and 6 deletions.
93 changes: 87 additions & 6 deletions src/components/engagement/engagement.edgedb.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { difference } from 'lodash';
import { ID, PublicOf, Session } from '~/common';
import { castToEnum, e, RepoFor } from '~/core/edgedb';
import {
CreateInternshipEngagement,
CreateLanguageEngagement,
EngagementListInput,
EngagementStatus,
IEngagement,
UpdateInternshipEngagement,
UpdateLanguageEngagement,
} from './dto';
import { EngagementRepository } from './engagement.repository';
Expand Down Expand Up @@ -70,23 +72,102 @@ export class EngagementEdgeDBRepository
return await this.db.run(query);
}

//getActualLanguageChanges = this.getActualChanges(LanguageEngagement);
async createInternshipEngagement(
input: CreateInternshipEngagement,
_session: Session,
_changeset?: ID,
) {
const { projectId, internId, mentorId, countryOfOriginId, ...props } =
input;

const project = e.cast(e.InternshipProject, e.uuid(projectId));
const intern = e.cast(e.User, e.uuid(internId));
const mentor = mentorId ? e.cast(e.User, e.uuid(mentorId)) : e.set();
const countryOfOrigin = countryOfOriginId
? e.cast(e.Location, e.uuid(countryOfOriginId))
: e.set();

const createdInternshipEngagement = e.insert(e.InternshipEngagement, {
project: project as any,
projectContext: project.projectContext,
intern: intern,
mentor: mentor,
countryOfOrigin: countryOfOrigin,
growthPlan: undefined as any, //TODO
...props,
});

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

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

getActualLanguageChanges = this.getActualChanges(LanguageEngagement);

async updateLanguage(
{ id, ...changes }: UpdateLanguageEngagement,
changes: UpdateLanguageEngagement,
_session: Session,
_changeset?: ID,
) {
return await this.defaults.update({ id, ...changes });
const { id, pnp, ...simpleChanges } = changes;

const languageEngagement = e.cast(e.LanguageEngagement, e.uuid(id));

if (pnp) {
//TODO
}

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

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

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

getActualInternshipChanges = this.getActualChanges(InternshipEngagement);

async updateInternship(
changes: 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);
}

async list(input: EngagementListInput, _session: Session, _changeset?: ID) {
return await this.defaults.list(input);
}

async listAllByProjectId(projectId: ID, _session: Session) {
const project = e.cast(e.TranslationProject, e.uuid(projectId));
const query = e.select(project, languageHydrate);
const project = e.cast(e.Project, e.uuid(projectId));
const query = e.select(project, hydrate);

return await this.db.run(query);
}
Expand All @@ -95,7 +176,7 @@ export class EngagementEdgeDBRepository
projectId: ID,
excludes: EngagementStatus[] = [],
) {
const project = e.cast(e.TranslationProject, e.uuid(projectId));
const project = e.cast(e.Project, e.uuid(projectId));

const ongoingExceptExclusions = e.cast(
e.Engagement.Status,
Expand Down

0 comments on commit 09d7db7

Please sign in to comment.