1
0
Fork 0
freesewing/sites/backend/src/controllers/sets.mjs
2023-04-30 19:01:24 +02:00

83 lines
2 KiB
JavaScript

import { SetModel } from '../models/set.mjs'
export function SetsController() {}
/*
* Create a measurements set for the authenticated user
* See: https://freesewing.dev/reference/backend/api
*/
SetsController.prototype.create = async (req, res, tools) => {
const Set = new SetModel(tools)
await Set.guardedCreate(req)
return Set.sendResponse(res)
}
/*
* Read a measurements set
* See: https://freesewing.dev/reference/backend/api
*/
SetsController.prototype.read = async (req, res, tools) => {
const Set = new SetModel(tools)
await Set.guardedRead(req)
return Set.sendResponse(res)
}
/*
* Get a list of measurements sets
* See: https://freesewing.dev/reference/backend/api
*/
SetsController.prototype.list = async (req, res, tools) => {
const Set = new SetModel(tools)
const sets = await Set.userSets(req.user.uid)
if (sets) Set.setResponse(200, 'success', { sets })
else Set.setResponse(404, 'notFound')
return Set.sendResponse(res)
}
/*
* Update a measurements set
* See: https://freesewing.dev/reference/backend/api
*/
SetsController.prototype.update = async (req, res, tools) => {
const Set = new SetModel(tools)
await Set.guardedUpdate(req)
return Set.sendResponse(res)
}
/*
* Remove a measurements set
* See: https://freesewing.dev/reference/backend/api
*/
SetsController.prototype.delete = async (req, res, tools) => {
const Set = new SetModel(tools)
await Set.guardedDelete(req)
return Set.sendResponse(res)
}
/*
* Clone a measurements set
* See: https://freesewing.dev/reference/backend/api
*/
SetsController.prototype.clone = async (req, res, tools) => {
const Set = new SetModel(tools)
await Set.guardedClone(req)
return Set.sendResponse(res)
}
/*
* Read a public measurements set
* See: https://freesewing.dev/reference/backend/api
*/
SetsController.prototype.readPublic = async (req, res, tools, format = 'json') => {
const Set = new SetModel(tools)
await Set.publicRead(req)
return format === 'yaml' ? Set.sendYamlResponse(res) : Set.sendResponse(res)
}