( projectId: string, provider: string, patch: Record<string, unknown> )
| 86 | } |
| 87 | |
| 88 | export async function updateProjectServiceData( |
| 89 | projectId: string, |
| 90 | provider: string, |
| 91 | patch: Record<string, unknown> |
| 92 | ) { |
| 93 | const existing = await prisma.projectServiceConnection.findFirst({ |
| 94 | where: { projectId, provider }, |
| 95 | }); |
| 96 | |
| 97 | const nextData = { |
| 98 | ...(existing ? (existing.serviceData ? JSON.parse(existing.serviceData) : {}) : {}), |
| 99 | ...patch, |
| 100 | }; |
| 101 | |
| 102 | if (existing) { |
| 103 | const updated = await prisma.projectServiceConnection.update({ |
| 104 | where: { id: existing.id }, |
| 105 | data: { serviceData: serializeServiceData(nextData) }, |
| 106 | }); |
| 107 | return deserializeServiceData(updated); |
| 108 | } |
| 109 | |
| 110 | const created = await prisma.projectServiceConnection.create({ |
| 111 | data: { |
| 112 | projectId, |
| 113 | provider, |
| 114 | status: 'connected', |
| 115 | serviceData: serializeServiceData(nextData), |
| 116 | }, |
| 117 | }); |
| 118 | |
| 119 | return deserializeServiceData(created); |
| 120 | } |
no test coverage detected