当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript phaethon.validate类代码示例

本文整理汇总了TypeScript中phaethon.validate的典型用法代码示例。如果您正苦于以下问题:TypeScript validate类的具体用法?TypeScript validate怎么用?TypeScript validate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了validate类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: login

export async function login(request: ServerRequest, session: Session): Promise<LoginResult> {
	const username = validate.expect(
		request.query["username"], validate.isString);
	const password = validate.expect(
		request.query["password"], validate.isString);
	const passwordHash = getPasswordHash(username, password);

	const results = await find(users, { username, passwordHash });
	if (results.length === 0) {
		return { ok: false, message: "Username or password incorrect" };
	}
	const user = results[0];
	session.userId = user._id;
	return { ok: true };
}
开发者ID:PacktPublishing,项目名称:TypeScript-Blueprints,代码行数:15,代码来源:user.ts

示例2: remove

export async function remove(request: ServerRequest, session: Session) {
	const user = await getUserOrError(session);
	const id = validate.expect(
		request.query["id"], validate.isString);
	await database.remove(database.notes,
		{ _id: new ObjectID(id), userId: user._id });
	return {};
}
开发者ID:PacktPublishing,项目名称:TypeScript-Blueprints,代码行数:8,代码来源:note.ts

示例3: update

export async function update(request: ServerRequest, session: Session): Promise<ItemResult> {
	const user = await getUserOrError(session);
	const id = validate.expect(
		request.query["id"], validate.isString);
	const content = validate.expect(
		request.query["content"], validate.isString);
	const note: Note = {
		_id: new ObjectID(id),
		userId: user._id,
		content
	};
	await database.update(database.notes,
		{ _id: new ObjectID(id), userId: user._id }, note);
	return {
		id: note._id.toHexString(),
		content: note.content
	};
}
开发者ID:PacktPublishing,项目名称:TypeScript-Blueprints,代码行数:18,代码来源:note.ts

示例4: insert

export async function insert(request: ServerRequest, session: Session): Promise<ItemResult> {
	const user = await getUserOrError(session);
	const content = validate.expect(
		request.query["content"], validate.isString);
	const note: Note = {
		_id: undefined,
		userId: user._id,
		content
	};
	await database.insert(database.notes, note);
	return {
		id: note._id.toHexString(),
		content: note.content
	};
}
开发者ID:PacktPublishing,项目名称:TypeScript-Blueprints,代码行数:15,代码来源:note.ts

示例5: find

export async function find(request: ServerRequest, session: Session): Promise<ItemResult> {
	const user = await getUserOrError(session);
	const id = validate.expect(
		request.query["id"], validate.isString);
	const notes = await database.find(database.notes,
		{ _id: new ObjectID(id), userId: user._id });
	if (notes.length === 0) {
		throw new ServerError(StatusCode.ClientErrorNotFound);
	}
	const note = notes[0];
	return {
		id: note._id.toHexString(),
		content: note.content
	};
}
开发者ID:PacktPublishing,项目名称:TypeScript-Blueprints,代码行数:15,代码来源:note.ts


注:本文中的phaethon.validate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。