本文整理汇总了TypeScript中joi.number函数的典型用法代码示例。如果您正苦于以下问题:TypeScript number函数的具体用法?TypeScript number怎么用?TypeScript number使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了number函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getTasks
public getTasks(): Hapi.IRouteAdditionalConfigurationOptions {
return {
handler: (request: Hapi.Request, reply: Hapi.IReply) => {
var top = request.query.top;
var skip = request.query.skip;
this.taskRepository.find({}, top, skip).then((tasks: Array<ITask>) => {
reply(tasks);
}).catch((error) => {
reply(Boom.badImplementation(error));
});
},
tags: ['api', 'tasks'],
description: 'Get all tasks.',
validate: {
query: {
top: Joi.number().default(5),
skip: Joi.number().default(0)
}
},
plugins: {
'hapi-swagger': {
responses: {
'200': {
'description': 'Returned Tasks.',
'schema': TaskModel.taskModel
}
}
}
}
};
}
示例2: validateInput
private validateInput(envConfig: EnvConfig): EnvConfig {
const envVarsSchema: Joi.ObjectSchema = Joi.object({
NODE_ENV: Joi.string()
.valid(['development', 'production', 'test', 'provision'])
.default('development'),
PORT: Joi.number().default(3000),
JWT_SECRET: Joi.string().required(),
JWT_EXPIRE: Joi.number().default(3600 * 24 * 7),
DB_TYPE: Joi.string().default('mysql'),
DB_HOST: Joi.string().default('localhost'),
DB_PORT: Joi.number().default(3306),
DB_USERNAME: Joi.string().required(),
DB_PASSWORD: Joi.string().required(),
DB_DATABASE_NAME: Joi.string().required(),
});
const { error, value: validatedEnvConfig } = Joi.validate(
envConfig,
envVarsSchema,
);
if (error) {
throw new Error(`Config validation error: ${error.message}`);
}
return validatedEnvConfig;
}
示例3: async
export const createGetAllRoute = (libs: UMServerLibs) => ({
method: 'GET',
path: '/api/uptime/pings',
options: {
validate: {
query: Joi.object({
dateRangeStart: Joi.number().required(),
dateRangeEnd: Joi.number().required(),
monitorId: Joi.string(),
size: Joi.number(),
sort: Joi.string(),
status: Joi.string(),
}),
},
tags: ['access:uptime'],
},
handler: async (request: any): Promise<PingResults> => {
const { size, sort, dateRangeStart, dateRangeEnd, monitorId, status } = request.query;
return await libs.pings.getAll(
request,
dateRangeStart,
dateRangeEnd,
monitorId,
status,
sort,
size
);
},
});
示例4: saveDepartment
async function saveDepartment(req, res) {
try {
let data = req.body.department;
let schema = {
id: Joi.number(),
name: Joi.string().required(),
budget: Joi.number().required(),
startDate: Joi.date().format(config.format.date),
instructorId: Joi.number().required()
};
let result = null;
let department = await helper.loadSchema(data, schema);
if (department.id) {
result = await departmentRepository.updateDepartment(department);
} else {
result = await departmentRepository.addDepartment(department);
}
department = await departmentRepository.getDepartmentById(result.id);
return helper.sendData({data: department}, res);
} catch (err) {
helper.sendFailureMessage(err, res);
}
}
示例5: saveCourse
async function saveCourse(req, res) {
try {
let courseData = req.body.course;
let schema = {
id: Joi.number(),
number: Joi.number().required(),
title: Joi.string().required(),
credits: Joi.number().required(),
departmentId: Joi.number().required()
};
let result = null;
let course = await helper.loadSchema(courseData, schema);
if (course.id) {
result = await courseRepository.updateCourse(courseData);
} else {
result = await courseRepository.addCourse(courseData);
}
course = await courseRepository.getCourseById(result.id);
return helper.sendData({data: course}, res);
} catch (err) {
helper.sendFailureMessage(err, res);
}
}
示例6: handler
export const createFindRoute = (prereqs: Prerequisites) => ({
path: '/api/saved_objects/_find',
method: 'GET',
config: {
pre: [prereqs.getSavedObjectsClient],
validate: {
query: Joi.object()
.keys({
per_page: Joi.number()
.min(0)
.default(20),
page: Joi.number()
.min(0)
.default(1),
type: Joi.array()
.items(Joi.string())
.single()
.required(),
search: Joi.string()
.allow('')
.optional(),
default_search_operator: Joi.string()
.valid('OR', 'AND')
.default('OR'),
search_fields: Joi.array()
.items(Joi.string())
.single(),
sort_field: Joi.string(),
has_reference: Joi.object()
.keys({
type: Joi.string().required(),
id: Joi.string().required(),
})
.optional(),
fields: Joi.array()
.items(Joi.string())
.single(),
})
.default(),
},
handler(request: FindRequest) {
const query = request.query;
return request.pre.savedObjectsClient.find({
perPage: query.per_page,
page: query.page,
type: query.type,
search: query.search,
defaultSearchOperator: query.default_search_operator,
searchFields: query.search_fields,
sortField: query.sort_field,
hasReference: query.has_reference,
fields: query.fields,
});
},
},
});
示例7: async
export const createTokensRoute = (libs: CMServerLibs) => ({
method: 'POST',
path: '/api/beats/enrollment_tokens',
licenseRequired: REQUIRED_LICENSES,
requiredRoles: ['beats_admin'],
config: {
validate: {
payload: Joi.object({
num_tokens: Joi.number()
.optional()
.default(DEFAULT_NUM_TOKENS)
.min(1),
}).allow(null),
},
},
handler: async (request: FrameworkRequest) => {
const numTokens = get(request, 'payload.num_tokens', DEFAULT_NUM_TOKENS);
try {
const tokens = await libs.tokens.createEnrollmentTokens(request.user, numTokens);
return { tokens };
} catch (err) {
libs.framework.log(err.message);
return Boom.internal();
}
},
});
示例8: saveStudent
async function saveStudent(req, res) {
try {
let data = req.body.student;
let schema = {
id: Joi.number(),
firstName: Joi.string().required(),
lastName: Joi.string().required(),
enrollmentDate: Joi.date()
};
let result = null;
let student = await helper.loadSchema(data, schema);
if (student.id) {
result = await studentRepository.updateStudent(student);
} else {
result = await studentRepository.addStudent(student);
}
return helper.sendData({data: result}, res);
} catch (err) {
helper.sendFailureMessage(err, res);
}
}
示例9: reply
export const createTokensRoute = (libs: CMServerLibs) => ({
method: 'POST',
path: '/api/beats/enrollment_tokens',
licenseRequired: true,
config: {
validate: {
payload: Joi.object({
num_tokens: Joi.number()
.optional()
.default(DEFAULT_NUM_TOKENS)
.min(1),
}).allow(null),
},
},
handler: async (request: FrameworkRequest, reply: any) => {
const numTokens = get(request, 'payload.num_tokens', DEFAULT_NUM_TOKENS);
try {
const tokens = await libs.tokens.createEnrollmentTokens(request.user, numTokens);
reply({ tokens });
} catch (err) {
// TODO move this to kibana route thing in adapter
return reply(wrapEsError(err));
}
},
});
示例10: RecordsController
exports.register = (server: Server, options: any, next: Function) => {
const controller = new RecordsController();
server.dependency("hapi-mongodb", (server: Server, next: Function) => {
controller.useDb(server.plugins["hapi-mongodb"].db);
return next();
});
server.route({
path: "/docs/{slug}/subdocs/{subdocId}/records/{recordId}",
method: "GET",
config: {
description: "Get a record",
notes: "Returns a record by the slug and subdocument id passed in the path",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 3
}
},
validate: {
params: {
slug: Joi.string()
.required()
.description("the slug for the document"),
subdocId: Joi.number()
.required()
.description("the id for the subdocument"),
recordId: Joi.number()
.required()
.description("the id for the record"),
}
},
pre: [
{ method: controller.getRecord, assign: "record" },
{ method: controller.getSerializedRecord, assign: "serialisedRecord" }
],
handler: controller.sendRecord
}
});
return next();
};