|
1 | 1 | import { Injectable } from '@nestjs/common'; |
2 | | -import { FeatureFlag } from '@prisma/client'; |
3 | | -import { FeatureFlagProto } from 'juno-proto'; |
| 2 | +import { FileServiceConfig } from '@prisma/client'; |
4 | 3 | import { PrismaService } from 'src/prisma.service'; |
| 4 | +import { FileConfigProto } from 'juno-proto'; |
5 | 5 |
|
6 | 6 | @Injectable() |
7 | | -export class FeatureFlagService { |
| 7 | +export class FileServiceConfigService { |
8 | 8 | constructor(private prisma: PrismaService) {} |
9 | 9 |
|
10 | | - async createFlag( |
11 | | - request: FeatureFlagProto.CreateFlagRequest, |
12 | | - ): Promise<FeatureFlag> { |
13 | | - return this.prisma.featureFlag.create({ |
| 10 | + async createConfig( |
| 11 | + configData: FileConfigProto.CreateFileServiceConfigRequest, |
| 12 | + ): Promise<FileServiceConfig> { |
| 13 | + return this.prisma.fileServiceConfig.create({ |
14 | 14 | data: { |
15 | | - id: request.id, |
16 | | - enabled: request.enabled, |
17 | | - description: request.description, |
| 15 | + Project: { |
| 16 | + connect: { |
| 17 | + id: Number(configData.projectId), |
| 18 | + }, |
| 19 | + }, |
| 20 | + environment: configData.environment, |
| 21 | + }, |
| 22 | + include: { |
| 23 | + Project: true, |
| 24 | + buckets: true, |
| 25 | + FileServiceFile: true, |
18 | 26 | }, |
19 | 27 | }); |
20 | 28 | } |
21 | 29 |
|
22 | | - async getFlag( |
23 | | - request: FeatureFlagProto.GetFlagRequest, |
24 | | - ): Promise<FeatureFlag> { |
25 | | - return this.prisma.featureFlag.findUnique({ |
| 30 | + async getConfig( |
| 31 | + req: FileConfigProto.GetFileServiceConfigRequest, |
| 32 | + ): Promise<FileServiceConfig | null> { |
| 33 | + return this.prisma.fileServiceConfig.findUnique({ |
26 | 34 | where: { |
27 | | - id: request.id, |
| 35 | + id_environment: { |
| 36 | + id: Number(req.id), |
| 37 | + environment: req.environment, |
| 38 | + }, |
| 39 | + }, |
| 40 | + include: { |
| 41 | + Project: true, |
| 42 | + buckets: true, |
| 43 | + FileServiceFile: true, |
28 | 44 | }, |
29 | 45 | }); |
30 | 46 | } |
31 | 47 |
|
32 | | - // only updates enabled/description if provided in the request (leave unchanged if undefined) |
33 | | - async setFlag( |
34 | | - request: FeatureFlagProto.SetFlagRequest, |
35 | | - ): Promise<FeatureFlag> { |
36 | | - return this.prisma.featureFlag.update({ |
| 48 | + async updateConfig( |
| 49 | + req: FileConfigProto.UpdateFileServiceConfigRequest, |
| 50 | + ): Promise<FileServiceConfig> { |
| 51 | + return this.prisma.fileServiceConfig.update({ |
37 | 52 | where: { |
38 | | - id: request.id, |
| 53 | + id_environment: { |
| 54 | + id: Number(req.id), |
| 55 | + environment: req.environment, |
| 56 | + }, |
39 | 57 | }, |
40 | 58 | data: { |
41 | | - ...(request.enabled !== undefined && { enabled: request.enabled }), |
42 | | - ...(request.description !== undefined && { |
43 | | - description: request.description, |
44 | | - }), |
| 59 | + buckets: { |
| 60 | + deleteMany: {}, |
| 61 | + // create: configData.buckets.map((bucket) => ({ |
| 62 | + // bucketName: bucket.bucketName, |
| 63 | + // })), |
| 64 | + }, |
| 65 | + Project: { |
| 66 | + connect: { |
| 67 | + id: Number(req.id), |
| 68 | + }, |
| 69 | + }, |
| 70 | + FileServiceFile: { |
| 71 | + deleteMany: {}, |
| 72 | + // create: |
| 73 | + // configData.files?.map((file) => ({ |
| 74 | + // fileId: { |
| 75 | + // path: file.fileId.path, |
| 76 | + // bucketName: file.fileId.bucketName, |
| 77 | + // configId: file.fileId.configId, |
| 78 | + // }, |
| 79 | + // metadata: file.metadata, |
| 80 | + // })) || [], |
| 81 | + }, |
| 82 | + }, |
| 83 | + include: { |
| 84 | + Project: true, |
| 85 | + buckets: true, |
| 86 | + FileServiceFile: true, |
45 | 87 | }, |
46 | 88 | }); |
47 | 89 | } |
48 | 90 |
|
49 | | - async deleteFlag( |
50 | | - request: FeatureFlagProto.DeleteFlagRequest, |
51 | | - ): Promise<FeatureFlagProto.DeleteFlagResponse> { |
52 | | - await this.prisma.featureFlag.delete({ |
| 91 | + async deleteConfig( |
| 92 | + request: FileConfigProto.DeleteFileServiceConfigRequest, |
| 93 | + ): Promise<FileServiceConfig> { |
| 94 | + return this.prisma.fileServiceConfig.delete({ |
53 | 95 | where: { |
54 | | - id: request.id, |
| 96 | + id_environment: { |
| 97 | + id: Number(request.id), |
| 98 | + environment: request.environment, |
| 99 | + }, |
| 100 | + }, |
| 101 | + include: { |
| 102 | + Project: true, |
| 103 | + buckets: true, |
| 104 | + FileServiceFile: true, |
55 | 105 | }, |
56 | 106 | }); |
57 | | - |
58 | | - return { |
59 | | - success: true, |
60 | | - }; |
61 | 107 | } |
62 | 108 | } |
0 commit comments