3 ms·
I am looking to release the setup I use for deployment but tbh it isn't tested (via tests, since I rely on typescript for most of my data shuttling) and there's
by yasserf 5y ago
I am looking to release the setup I use for deployment but tbh it isn't tested (via tests, since I rely on typescript for most of my data shuttling) and there's alot to it so need to write alot of documentation which i don't have time for.
But, the jist is, we APIs like this (this can be improved with less generic json schemas):
export const updateSamf: APIFunction<UpdateSamf, void> = async ({ database }, { samfId, ...data }) => {
if (Object.keys(data).length === 0) {
throw new InvalidParametersError('No fields to update')
}
if (data.title && data.title.length < 3) {
throw new InvalidParametersError('Title needs to be at least 3 characters')
}
if (data.tags) {
data.tags = data.tags.map((t) => t.toLowerCase())
}
await database.crudUpdate<Samf>('samf', data, { samfId }, new SamfNotFoundError())
if (data.cover && previousCover) {
await content.delete(previousCover)
}
}
export const routes: APIRoutes = [{
type: 'patch',
route: StudioRoutePath.SAMF_CRUD,
func: updateSamf,
schema: 'UpdateSamf',
permissions: isSamfOwner
}]