Skip to content

Commit 19e8270

Browse files
bryanjnelsonCarsonF
authored andcommitted
[EdgeDB] Finish Engagement queries
1 parent ff509e4 commit 19e8270

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

src/components/engagement/engagement.edgedb.repository.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { Injectable, Type } from '@nestjs/common';
22
import { ModuleRef } from '@nestjs/core';
33
import { LazyGetter } from 'lazy-get-decorator';
4-
import { PublicOf } from '~/common';
4+
import { difference } from 'lodash';
5+
import { ID, PublicOf } from '~/common';
56
import { grabInstances } from '~/common/instance-maps';
67
import { e, RepoFor } from '~/core/edgedb';
78
import {
89
EngagementConcretes as ConcreteTypes,
910
CreateInternshipEngagement,
1011
CreateLanguageEngagement,
1112
IEngagement,
13+
EngagementStatus as Status,
1214
UpdateInternshipEngagement,
1315
UpdateLanguageEngagement,
1416
} from './dto';
@@ -77,15 +79,33 @@ export const ConcreteRepos = {
7779
ConcreteTypes.LanguageEngagement,
7880
{
7981
hydrate: languageHydrate,
82+
omit: ['create'],
8083
},
81-
) {},
84+
) {
85+
async create(input: CreateLanguageEngagement) {
86+
const project = e.cast(e.TranslationProject, e.uuid(input.projectId));
87+
return await this.defaults.create({
88+
...input,
89+
projectContext: project.projectContext,
90+
});
91+
}
92+
},
8293

8394
InternshipEngagement: class InternshipEngagementRepository extends RepoFor(
8495
ConcreteTypes.InternshipEngagement,
8596
{
8697
hydrate: internshipHydrate,
98+
omit: ['create'],
8799
},
88-
) {},
100+
) {
101+
async create(input: CreateInternshipEngagement) {
102+
const project = e.cast(e.InternshipProject, e.uuid(input.projectId));
103+
return await this.defaults.create({
104+
...input,
105+
projectContext: project.projectContext,
106+
});
107+
}
108+
},
89109
} satisfies Record<keyof typeof ConcreteTypes, Type>;
90110

91111
@Injectable()
@@ -127,4 +147,33 @@ export class EngagementEdgeDBRepository
127147
async updateInternship(input: UpdateInternshipEngagement) {
128148
return await this.concretes.InternshipEngagement.update(input);
129149
}
150+
151+
async listAllByProjectId(projectId: ID) {
152+
const project = e.cast(e.Project, e.uuid(projectId));
153+
const query = e.select(e.Engagement, (eng) => ({
154+
filter: e.op(eng.project, '=', project),
155+
...hydrate(eng),
156+
}));
157+
158+
return await this.db.run(query);
159+
}
160+
161+
async getOngoingEngagementIds(projectId: ID, excludes: Status[] = []) {
162+
const project = e.cast(e.Project, e.uuid(projectId));
163+
164+
const ongoingExceptExclusions = e.cast(
165+
e.Engagement.Status,
166+
e.set(...difference([...Status.Ongoing], excludes)),
167+
);
168+
169+
const engagements = e.select(e.Engagement, (eng) => ({
170+
filter: e.op(
171+
e.op(eng.project, '=', project),
172+
'and',
173+
e.op(eng.status, 'in', ongoingExceptExclusions),
174+
),
175+
}));
176+
177+
return await this.db.run(engagements.id);
178+
}
130179
}

0 commit comments

Comments
 (0)