Added a sample implementation for validation schemas
This commit is contained in:
parent
988667bde8
commit
0374d7bccb
7 changed files with 122 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
|||
const { getConfig } = require("../utils/configManager");
|
||||
const MySQLDatabase = require("./mysql");
|
||||
const SQLiteDatabase = require("./sqlite");
|
||||
const { getConfig } = require("../utils/configManager");
|
||||
|
||||
let db;
|
||||
|
||||
|
|
|
|||
21
src/schemas/auth.js
Normal file
21
src/schemas/auth.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
const Ajv = require("ajv");
|
||||
const ajv = new Ajv();
|
||||
|
||||
// --- Schemas ---
|
||||
|
||||
const AuthUserSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
email: { type: 'string', format: 'email' },
|
||||
password: { type: 'string', minLength: 3, maxLength: 30 },
|
||||
},
|
||||
required: ['email', 'password'],
|
||||
additionalProperties: false
|
||||
};
|
||||
|
||||
const validateAuthUserData = ajv.compile(AuthUserSchema);
|
||||
|
||||
|
||||
// --- Exports ---
|
||||
|
||||
module.exports = { validateAuthUserData, validateAuthNodeData };
|
||||
21
src/schemas/mod.js
Normal file
21
src/schemas/mod.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
const Ajv = require("ajv");
|
||||
const ajv = new Ajv();
|
||||
|
||||
// --- Schemas ---
|
||||
//TODO
|
||||
|
||||
const newModSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: { type: 'string'},
|
||||
},
|
||||
required: ['name'],
|
||||
additionalProperties: false
|
||||
};
|
||||
|
||||
const validateNewModData = ajv.compile(newModSchema);
|
||||
|
||||
|
||||
// --- Exports ---
|
||||
|
||||
module.exports = { validateNewModData };
|
||||
21
src/schemas/modpack.js
Normal file
21
src/schemas/modpack.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
const Ajv = require("ajv");
|
||||
const ajv = new Ajv();
|
||||
|
||||
// --- Schemas ---
|
||||
//TODO
|
||||
|
||||
const newModpackSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: { type: 'string'},
|
||||
},
|
||||
required: ['name'],
|
||||
additionalProperties: false
|
||||
};
|
||||
|
||||
const validateNewModpackData = ajv.compile(newModpackSchema);
|
||||
|
||||
|
||||
// --- Exports ---
|
||||
|
||||
module.exports = { validateNewModpackData };
|
||||
23
src/schemas/user.js
Normal file
23
src/schemas/user.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
const Ajv = require("ajv");
|
||||
const ajv = new Ajv();
|
||||
|
||||
// --- Schemas ---
|
||||
//TODO
|
||||
|
||||
const newUserSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
email: { type: 'string', format: 'email' },
|
||||
name: { type: 'string' },
|
||||
password: { type: 'string', minLength: 3, maxLength: 30 },
|
||||
},
|
||||
required: ['name', 'email', 'password'],
|
||||
additionalProperties: false
|
||||
};
|
||||
|
||||
const validateNewUserData = ajv.compile(newUserSchema);
|
||||
|
||||
|
||||
// --- Exports ---
|
||||
|
||||
module.exports = { validateNewUserData };
|
||||
Loading…
Add table
Add a link
Reference in a new issue