mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
feat: validator decorator
This commit is contained in:
1 parent
ba03d7a7bf
commit
4e85b696c0
23 files changed
+313
-180
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import * as user from '../model/user';
|
||||
import * as system from '../model/system';
|
||||
|
||||
export const description = 'Create a new user';
|
||||
|
||||
export async function run({
|
||||
uname, password, mail, uid,
|
||||
}) {
|
||||
if (!uid) uid = await system.inc('user');
|
||||
else uid = parseInt(uid, 10);
|
||||
if (Number.isNaN(uid)) throw new Error('uid');
|
||||
await user.create({
|
||||
uid, uname, password, mail, regip: '127.0.0.1',
|
||||
});
|
||||
return uid;
|
||||
}
|
||||
|
||||
export const validate = {
|
||||
uname: { $type: 'string' },
|
||||
password: { $type: 'string' },
|
||||
mail: { $type: 'string' },
|
||||
};
|
||||
|
||||
global.Hydro.script.register = { run, description, validate };
|
||||
Reference in new issue
Block a user