Skip to content

Commit 1d7df80

Browse files
committed
Add file and bucket info to config retrieval
1 parent 693fb5d commit 1d7df80

1 file changed

Lines changed: 58 additions & 3 deletions

File tree

‎packages/db-service/src/modules/file_config/file_config.controller.ts‎

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { status } from '@grpc/grpc-js';
22
import { Controller } from '@nestjs/common';
33
import { RpcException } from '@nestjs/microservices';
44
import { Prisma } from '@prisma/client';
5-
import { FileConfigProto } from 'juno-proto';
5+
import { FileBucketProto, FileConfigProto, FileProto } from 'juno-proto';
66
import { FileServiceConfigService } from './file_config.service';
77

88
@Controller()
@@ -61,11 +61,66 @@ export class FileConfigController
6161
});
6262
}
6363

64+
// TODO: find a way to hook this up with the standard proto definitions
65+
type PrismaConfigWithRelations = {
66+
id: number;
67+
environment: string;
68+
FileServiceFile: Array<{
69+
path: string;
70+
bucketName: string;
71+
configId: number;
72+
configEnv: string;
73+
metadata: string;
74+
}>;
75+
buckets: Array<{
76+
name: string;
77+
configId: number;
78+
configEnv: string;
79+
fileProviderName: string;
80+
}>;
81+
};
82+
83+
const prismaConfig = config as unknown as PrismaConfigWithRelations;
84+
85+
const files: FileProto.File[] = (prismaConfig.FileServiceFile ?? []).map(
86+
(f) => ({
87+
fileId: {
88+
path: f.path,
89+
bucketName: f.bucketName,
90+
configId: f.configId,
91+
configEnv: f.configEnv,
92+
},
93+
metadata: f.metadata,
94+
}),
95+
);
96+
97+
const buckets: FileBucketProto.Bucket[] = (prismaConfig.buckets ?? []).map(
98+
(b) => ({
99+
name: b.name,
100+
configId: b.configId,
101+
configEnv: b.configEnv,
102+
fileProviderName: b.fileProviderName,
103+
FileServiceFile: (prismaConfig.FileServiceFile ?? [])
104+
.filter(
105+
(f) =>
106+
f.bucketName === b.name &&
107+
f.configId === b.configId &&
108+
f.configEnv === b.configEnv,
109+
)
110+
.map((f) => ({
111+
path: f.path,
112+
bucketName: f.bucketName,
113+
configId: f.configId,
114+
configEnv: f.configEnv,
115+
})),
116+
}),
117+
);
118+
64119
return {
65120
id: config.id,
66121
environment: config.environment,
67-
files: [],
68-
buckets: [],
122+
files,
123+
buckets,
69124
};
70125
}
71126

0 commit comments

Comments
 (0)