From 0223b8e7ac5a6890f4674ffe01feef18d3c98d39 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Tue, 14 Jan 2025 20:49:08 +0100 Subject: [PATCH] Add defaultSeed and updateStaticData function returns (#202) # Add defaultSeed and updateStaticData function returns ## :recycle: Current situation & Problem ENGAGE Web Dashboards needs these types exposed to call functions safely. ## :gear: Release Notes * Add defaultSeed and updateStaticData function types ### Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md). --- functions/models/src/functions/defaultSeed.ts | 3 +++ .../models/src/functions/updateStaticData.ts | 1 + functions/src/functions/defaultSeed.ts | 21 ++++++++++++------- functions/src/functions/updateStaticData.ts | 9 ++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/functions/models/src/functions/defaultSeed.ts b/functions/models/src/functions/defaultSeed.ts index 7e6f0bc6..12e0c69f 100644 --- a/functions/models/src/functions/defaultSeed.ts +++ b/functions/models/src/functions/defaultSeed.ts @@ -57,3 +57,6 @@ export const defaultSeedInputSchema = z.object({ [], ), }) + +export type DefaultSeedInput = z.input +export type DefaultSeedOutput = Record diff --git a/functions/models/src/functions/updateStaticData.ts b/functions/models/src/functions/updateStaticData.ts index f06c68e7..5e3a326f 100644 --- a/functions/models/src/functions/updateStaticData.ts +++ b/functions/models/src/functions/updateStaticData.ts @@ -35,3 +35,4 @@ export const updateStaticDataInputSchema = z.object({ ), }) export type UpdateStaticDataInput = z.input +export type UpdateStaticDataOutput = Record diff --git a/functions/src/functions/defaultSeed.ts b/functions/src/functions/defaultSeed.ts index 0bf2b5da..441a2862 100644 --- a/functions/src/functions/defaultSeed.ts +++ b/functions/src/functions/defaultSeed.ts @@ -9,6 +9,7 @@ import { DebugDataComponent, defaultSeedInputSchema, + type DefaultSeedOutput, UserDebugDataComponent, UserType, } from '@stanfordbdhg/engagehf-models' @@ -187,13 +188,17 @@ export const defaultSeed = defaultSeedInputSchema, async (_, data, response) => { await _defaultSeed(getServiceFactory(), data) - response.write('Success', 'utf8') - response.end() + const result: DefaultSeedOutput = {} + response.send({ result }) + }, + ) + : validatedOnCall( + 'defaultSeed', + defaultSeedInputSchema, + async (request): Promise => { + const factory = getServiceFactory() + factory.credential(request.auth).check(UserRole.admin) + await _defaultSeed(factory, request.data) + return {} }, ) - : validatedOnCall('defaultSeed', defaultSeedInputSchema, async (request) => { - const factory = getServiceFactory() - factory.credential(request.auth).check(UserRole.admin) - await _defaultSeed(factory, request.data) - return 'Success' - }) diff --git a/functions/src/functions/updateStaticData.ts b/functions/src/functions/updateStaticData.ts index 7795930c..5bfb3db5 100644 --- a/functions/src/functions/updateStaticData.ts +++ b/functions/src/functions/updateStaticData.ts @@ -9,6 +9,7 @@ import { StaticDataComponent, updateStaticDataInputSchema, + type UpdateStaticDataOutput, } from '@stanfordbdhg/engagehf-models' import { type z } from 'zod' import { validatedOnCall, validatedOnRequest } from './helpers.js' @@ -43,17 +44,17 @@ export const updateStaticData = updateStaticDataInputSchema, async (_, data, response) => { await _updateStaticData(getServiceFactory(), data) - response.write('Success', 'utf8') - response.end() + const result: UpdateStaticDataOutput = {} + response.send({ result }) }, ) : validatedOnCall( 'updateStaticData', updateStaticDataInputSchema, - async (request) => { + async (request): Promise => { const factory = getServiceFactory() factory.credential(request.auth).check(UserRole.admin) await _updateStaticData(factory, request.data) - return 'Success' + return {} }, )