|
1 | 1 | import { Injectable, Type } from '@nestjs/common';
|
2 | 2 | import { ModuleRef } from '@nestjs/core';
|
3 | 3 | import { LazyGetter } from 'lazy-get-decorator';
|
4 |
| -import { PublicOf } from '~/common'; |
| 4 | +import { difference } from 'lodash'; |
| 5 | +import { ID, PublicOf } from '~/common'; |
5 | 6 | import { grabInstances } from '~/common/instance-maps';
|
6 | 7 | import { e, RepoFor } from '~/core/edgedb';
|
7 | 8 | import {
|
8 | 9 | EngagementConcretes as ConcreteTypes,
|
9 | 10 | CreateInternshipEngagement,
|
10 | 11 | CreateLanguageEngagement,
|
11 | 12 | IEngagement,
|
| 13 | + EngagementStatus as Status, |
12 | 14 | UpdateInternshipEngagement,
|
13 | 15 | UpdateLanguageEngagement,
|
14 | 16 | } from './dto';
|
@@ -77,15 +79,33 @@ export const ConcreteRepos = {
|
77 | 79 | ConcreteTypes.LanguageEngagement,
|
78 | 80 | {
|
79 | 81 | hydrate: languageHydrate,
|
| 82 | + omit: ['create'], |
80 | 83 | },
|
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 | + }, |
82 | 93 |
|
83 | 94 | InternshipEngagement: class InternshipEngagementRepository extends RepoFor(
|
84 | 95 | ConcreteTypes.InternshipEngagement,
|
85 | 96 | {
|
86 | 97 | hydrate: internshipHydrate,
|
| 98 | + omit: ['create'], |
87 | 99 | },
|
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 | + }, |
89 | 109 | } satisfies Record<keyof typeof ConcreteTypes, Type>;
|
90 | 110 |
|
91 | 111 | @Injectable()
|
@@ -127,4 +147,33 @@ export class EngagementEdgeDBRepository
|
127 | 147 | async updateInternship(input: UpdateInternshipEngagement) {
|
128 | 148 | return await this.concretes.InternshipEngagement.update(input);
|
129 | 149 | }
|
| 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 | + } |
130 | 179 | }
|
0 commit comments