implemented changelog
This commit is contained in:
50
src/routes/validate/root.ts
Normal file
50
src/routes/validate/root.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import Joi from '@hapi/joi';
|
||||
import IdValidate from './id';
|
||||
|
||||
export default class RootValidate { // validate input for root methods
|
||||
private static changelog = {
|
||||
timestamp: Joi.date()
|
||||
.iso()
|
||||
.min('1970-01-01T00:00:00.000Z'),
|
||||
|
||||
page: Joi.number()
|
||||
.integer()
|
||||
.min(0)
|
||||
.default(0),
|
||||
|
||||
pagesize: Joi.number()
|
||||
.integer()
|
||||
.min(0)
|
||||
.default(25),
|
||||
|
||||
action: Joi.string(),
|
||||
|
||||
collection: Joi.string(),
|
||||
|
||||
conditions: Joi.object(),
|
||||
|
||||
data: Joi.object()
|
||||
};
|
||||
|
||||
static changelogParams (data) {
|
||||
return Joi.object({
|
||||
timestamp: this.changelog.timestamp.required(),
|
||||
page: this.changelog.page,
|
||||
pagesize: this.changelog.pagesize
|
||||
}).validate(data);
|
||||
}
|
||||
|
||||
static changelogOutput (data) {
|
||||
data.date = data._id.getTimestamp();
|
||||
data.collection = data.collectionName;
|
||||
data = IdValidate.stringify(data);
|
||||
const {value, error} = Joi.object({
|
||||
date: this.changelog.timestamp,
|
||||
action: this.changelog.action,
|
||||
collection: this.changelog.collection,
|
||||
conditions: this.changelog.conditions,
|
||||
data: this.changelog.data,
|
||||
}).validate(data, {stripUnknown: true});
|
||||
return error !== undefined? null : value;
|
||||
}
|
||||
}
|
@ -69,7 +69,7 @@ export default class SampleValidate {
|
||||
}
|
||||
else if (param === 'new-admin') {
|
||||
return Joi.object({
|
||||
number: this.sample.number.required(),
|
||||
number: this.sample.number,
|
||||
color: this.sample.color.required(),
|
||||
type: this.sample.type.required(),
|
||||
batch: this.sample.batch.required(),
|
||||
|
Reference in New Issue
Block a user