當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。