11import type database from "~/database" ;
22import type { ServiceDTO } from "~/models/service" ;
33import { pluck } from "~/utils/object" ;
4+ import createRecord from "~/utils/record" ;
45
56export default async function getService ( db : typeof database , serviceId : string ) {
67 const service = await db . query . services . findFirst ( {
@@ -26,7 +27,6 @@ export default async function getService(db: typeof database, serviceId: string)
2627 networks : {
2728 columns : {
2829 id : true ,
29- kind : true ,
3030 } ,
3131 } ,
3232 providerlinks : {
@@ -73,9 +73,9 @@ export default async function getService(db: typeof database, serviceId: string)
7373 const { ports, environmentVariables, volumes, networks, providerlinks, clientLinks, ...others } = service ;
7474 return {
7575 ...others ,
76- environmentVariables : Object . fromEntries ( environmentVariables . map ( ( { key , value } ) => [ key , value ] as const ) ) ,
76+ environmentVariables : createRecord ( environmentVariables , " key" , " value" ) ,
7777 ports : Object . fromEntries ( ports . map ( ( { external, internal } ) => [ external , internal . toString ( ) ] as const ) ) ,
78- volumes : Object . fromEntries ( volumes . map ( ( { id , containerPath } ) => [ id , containerPath ] as const ) ) ,
78+ volumes : createRecord ( volumes , "id" , " containerPath" ) ,
7979 networkIds : pluck ( networks , "id" ) ,
8080 providers : pluck ( providerlinks , "provider" ) . map ( ( {
8181 networks : providerNetworks ,
@@ -84,7 +84,7 @@ export default async function getService(db: typeof database, serviceId: string)
8484 } ) => ( {
8585 ...otherPropsOfProvider ,
8686 networkIds : pluck ( providerNetworks , "id" ) ,
87- variables : Object . fromEntries ( providerVariables . map ( entry => [ entry . key , entry . value ] as const ) ) ,
87+ variables : createRecord ( providerVariables , " key" , " value" ) ,
8888 } ) ) ,
8989 clients : pluck ( clientLinks , "client" ) ,
9090 } satisfies ServiceDTO ;
0 commit comments