-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFractionEntityService.ts
More file actions
83 lines (78 loc) · 2.61 KB
/
Copy pathFractionEntityService.ts
File metadata and controls
83 lines (78 loc) · 2.61 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Selectable } from "kysely";
import { injectable } from "tsyringe";
import { kyselyCaching } from "../../../client/kysely.js";
import { GetFractionsArgs } from "../../../graphql/schemas/args/fractionArgs.js";
import { CachingDatabase } from "../../../types/kyselySupabaseCaching.js";
import {
createEntityService,
type EntityService,
} from "./EntityServiceFactory.js";
/** Type representing a selected fraction record from the database */
export type FractionSelect = Selectable<CachingDatabase["fractions_view"]>;
/**
* Service class for managing fraction entities in the database.
* Handles CRUD operations for hypercert fractions, which represent ownership units of hypercerts.
*
* This service provides methods to:
* - Query multiple fractions with filtering and pagination
* - Retrieve single fraction records by various criteria
*
* @injectable
*/
@injectable()
export class FractionService {
/** The underlying entity service instance for database operations */
private entityService: EntityService<
CachingDatabase["fractions_view"],
GetFractionsArgs
>;
/**
* Initializes a new instance of the FractionService.
* Creates an EntityService instance for the fractions_view table.
*/
constructor() {
this.entityService = createEntityService<
CachingDatabase,
"fractions_view",
GetFractionsArgs
>("fractions_view", "FractionEntityService", kyselyCaching);
}
/**
* Retrieves multiple fractions based on the provided arguments.
*
* @param args - Query arguments for filtering fractions
* @returns Promise resolving to an object containing:
* - data: Array of fraction records
* - count: Total number of matching records
* @throws {Error} If the database query fails
*
* @example
* ```typescript
* // Get all fractions owned by a specific address
* const result = await fractionService.getFractions({
* where: { owner_address: { eq: "0x..." } }
* });
* ```
*/
async getFractions(args: GetFractionsArgs) {
return this.entityService.getMany(args);
}
/**
* Retrieves a single fraction based on the provided arguments.
*
* @param args - Query arguments for filtering the fraction
* @returns Promise resolving to a single fraction record or undefined if not found
* @throws {Error} If the database query fails
*
* @example
* ```typescript
* // Get a specific fraction by ID
* const fraction = await fractionService.getFraction({
* where: { units: { eq: 100n } }
* });
* ```
*/
async getFraction(args: GetFractionsArgs) {
return this.entityService.getSingle(args);
}
}