YishTish 9d96ab0983
Nodejs express js packages update (#5675)
* Updated to new nodejs packages, depending heavily on express-openapi-validator. Requires quite a change in code.
Updated the business-logic in the controllers/Controller.js file.
Logger now records also timestamp of events.
Files are uploaded according to definition in config.js file

* Removed commented-out code; Changed openApi document extensions to suit new express-openapi-validator definition; multipart and file uploading is supported now; Automatic response returns the values the were sent in the request

* fixed README documentation, fixed a mistage in package.json/mustache

* added generated files that were created when running the ./bin/test file
2020-03-24 17:37:18 +08:00

180 lines
3.8 KiB
JavaScript

/* eslint-disable no-unused-vars */
const Service = require('./Service');
/**
* Create user
* This can only be done by the logged in user.
*
* body User Created user object
* no response value expected for this operation
* */
const createUser = ({ body }) => new Promise(
async (resolve, reject) => {
try {
resolve(Service.successResponse({
body,
}));
} catch (e) {
reject(Service.rejectResponse(
e.message || 'Invalid input',
e.status || 405,
));
}
},
);
/**
* Creates list of users with given input array
*
* body List List of user object
* no response value expected for this operation
* */
const createUsersWithArrayInput = ({ body }) => new Promise(
async (resolve, reject) => {
try {
resolve(Service.successResponse({
body,
}));
} catch (e) {
reject(Service.rejectResponse(
e.message || 'Invalid input',
e.status || 405,
));
}
},
);
/**
* Creates list of users with given input array
*
* body List List of user object
* no response value expected for this operation
* */
const createUsersWithListInput = ({ body }) => new Promise(
async (resolve, reject) => {
try {
resolve(Service.successResponse({
body,
}));
} catch (e) {
reject(Service.rejectResponse(
e.message || 'Invalid input',
e.status || 405,
));
}
},
);
/**
* Delete user
* This can only be done by the logged in user.
*
* username String The name that needs to be deleted
* no response value expected for this operation
* */
const deleteUser = ({ username }) => new Promise(
async (resolve, reject) => {
try {
resolve(Service.successResponse({
username,
}));
} catch (e) {
reject(Service.rejectResponse(
e.message || 'Invalid input',
e.status || 405,
));
}
},
);
/**
* Get user by user name
*
* username String The name that needs to be fetched. Use user1 for testing.
* returns User
* */
const getUserByName = ({ username }) => new Promise(
async (resolve, reject) => {
try {
resolve(Service.successResponse({
username,
}));
} catch (e) {
reject(Service.rejectResponse(
e.message || 'Invalid input',
e.status || 405,
));
}
},
);
/**
* Logs user into the system
*
* username String The user name for login
* password String The password for login in clear text
* returns String
* */
const loginUser = ({ username, password }) => new Promise(
async (resolve, reject) => {
try {
resolve(Service.successResponse({
username,
password,
}));
} catch (e) {
reject(Service.rejectResponse(
e.message || 'Invalid input',
e.status || 405,
));
}
},
);
/**
* Logs out current logged in user session
*
* no response value expected for this operation
* */
const logoutUser = () => new Promise(
async (resolve, reject) => {
try {
resolve(Service.successResponse({
}));
} catch (e) {
reject(Service.rejectResponse(
e.message || 'Invalid input',
e.status || 405,
));
}
},
);
/**
* Updated user
* This can only be done by the logged in user.
*
* username String name that need to be deleted
* body User Updated user object
* no response value expected for this operation
* */
const updateUser = ({ username, body }) => new Promise(
async (resolve, reject) => {
try {
resolve(Service.successResponse({
username,
body,
}));
} catch (e) {
reject(Service.rejectResponse(
e.message || 'Invalid input',
e.status || 405,
));
}
},
);
module.exports = {
createUser,
createUsersWithArrayInput,
createUsersWithListInput,
deleteUser,
getUserByName,
loginUser,
logoutUser,
updateUser,
};