mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
chore(): rename website/src -> website/server and website/public -> website/client (#7199)
This commit is contained in:
40
website/server/controllers/api-v3/modelsPaths.js
Normal file
40
website/server/controllers/api-v3/modelsPaths.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
let api = {};
|
||||
|
||||
let tasksModels = ['habit', 'daily', 'todo', 'reward'];
|
||||
let allModels = ['user', 'tag', 'challenge', 'group'].concat(tasksModels);
|
||||
|
||||
/**
|
||||
* @api {get} /api/v3s/models/:model/paths Get all paths for the specified model.
|
||||
* @apiDescription Doesn't require authentication
|
||||
* @apiVersion 3.0.0
|
||||
* @apiName GetUserModelPaths
|
||||
* @apiGroup Meta
|
||||
*
|
||||
* @apiParam {string="user","group","challenge","tag","habit","daily","todo","reward"} model The name of the model
|
||||
*
|
||||
* @apiSuccess {object} data A key-value object made of fieldPath: fieldType (like {'field.nested': Boolean})
|
||||
*/
|
||||
api.getModelPaths = {
|
||||
method: 'GET',
|
||||
url: '/models/:model/paths',
|
||||
async handler (req, res) {
|
||||
req.checkParams('model', res.t('modelNotFound')).notEmpty().isIn(allModels);
|
||||
|
||||
let validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
let model = req.params.model;
|
||||
// tasks models are lowercase, the others have the first letter uppercase (User, Group)
|
||||
if (tasksModels.indexOf(model) === -1) {
|
||||
model = model.charAt(0).toUpperCase() + model.slice(1);
|
||||
}
|
||||
|
||||
model = mongoose.model(model);
|
||||
|
||||
res.respond(200, model.getModelPaths());
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = api;
|
||||
Reference in New Issue
Block a user