-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreleaseFactory.ts
More file actions
51 lines (46 loc) · 1.42 KB
/
releaseFactory.ts
File metadata and controls
51 lines (46 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Collection, Db } from 'mongodb';
import { ReleaseDBScheme } from '@hawk.so/types';
import DataLoaders from '../dataLoaders';
export default class ReleasesFactory {
/**
* Releases collection
*/
private collection: Collection<ReleaseDBScheme>;
/**
* DataLoader for releases
*/
private dataLoaders: DataLoaders;
/**
* Creates an instance of the releases factory
* @param dbConnection - database connection
* @param dataLoaders - DataLoaders instance for request batching
*/
constructor(dbConnection: Db, dataLoaders: DataLoaders) {
this.collection = dbConnection.collection('releases');
this.dataLoaders = dataLoaders;
}
/**
* Get a release by its identifier using DataLoader
* @param releaseId - release identifier
*/
public async findById(releaseId: string): Promise<ReleaseDBScheme | null> {
try {
return await this.dataLoaders.releaseById.load(releaseId);
} catch (error) {
console.error(`[ReleasesFactory] Error in findById:`, error);
throw error;
}
}
/**
* Get releases by project identifier
* @param projectId - project identifier
*/
public async findManyByProjectId(projectId: string): Promise<ReleaseDBScheme[]> {
try {
return await this.collection.find({ projectId: projectId }).toArray();
} catch (error) {
console.error(`[ReleasesFactory] Error in findManyByProjectId:`, error);
throw error;
}
}
}