本文整理匯總了TypeScript中express.Response.json方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.json方法的具體用法?TypeScript Response.json怎麽用?TypeScript Response.json使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Response
的用法示例。
在下文中一共展示了Response.json方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: update
public async update (req: Request, res: Response): Promise<void> {
let success = false;
let error = "";
const category: Category = this.getCategoryFromBody(req.body);
if (this.m_categoryHandler.isEntityValid(category, true)) {
success = await this.m_categoryHandler.update(category);
if (!success) {
error = "Failed to update the category in database.";
}
}
else {
error = "Invalid category.";
}
res.json({
success: success,
error: error
});
}
示例2: removePhrase
public async removePhrase (req: Request, res: Response): Promise<void> {
const phrase = this.getPhraseFromBody(req.body);
let success = false;
let error = "";
if (Number.isInteger(phrase.id) && phrase.id > 0) {
success = await this.m_phraseHandler.remove(phrase);
if (!success) {
error = "Failed to remove the phrase from database.";
}
}
else {
error = "Invalid phrase.";
}
res.json({
success: success,
error: error
});
}
示例3: createPhrase
public async createPhrase (req: Request, res: Response): Promise<void> {
let phrase: Phrase = this.getPhraseFromBody(req.body);
let error = "";
if (this.m_phraseHandler.isEntityValid(phrase, false)) {
const success = await this.m_phraseHandler.add(phrase);
if (!success) {
phrase = null;
error = "Failed to add the phrase to database.";
}
}
else {
phrase = null;
error = "Invalid phrase.";
}
res.json({
phrase: phrase,
error: error
});
}
示例4: removePhraseFromQuiz
public async removePhraseFromQuiz (req: Request, res: Response): Promise<void> {
const quizId = parseInt(req.body.quizId, 10);
const phraseId = parseInt(req.body.phraseId, 10);
let error = "";
let success = false;
if (Number.isInteger(quizId) && Number.isInteger(phraseId)) {
success = await this.m_quizPhraseHandler.removePhraseFromQuiz(quizId, phraseId);
if (!success) {
error = "Failed to remove phrase in the database from the quiz.";
}
}
else {
error = "Invalid quiz id or phrase id.";
}
res.json({
error: error,
success: success
});
}
示例5:
}).then((user: IUserModel) => {
//verify user was found
if (user === null) {
res.status(404).json({
"status":"not_found"
});
return;
}
let {firstName,lastName,email,createdAt,...x} = user;
//send json response
res.json({
"status":"ok",
"count":1,
"user":{
firstName,
lastName,
email,
createdAt
}
});
}).catch((err)=>{
示例6: renderError
public static renderError(err: any, req: Request, res: Response, next: NextFunction): any {
if (err instanceof ErrorDTO) {
if (err.details) {
Logger.warn('Handled error:');
console.log(err);
if (!(req.session.user && req.session.user.role >= UserRoles.Developer)) {
delete (err.details);
} else {
try {
err.details = err.details.toString() || err.details;
} catch (err) {
console.error(err);
}
}
}
const message = new Message<any>(err, null);
return res.json(message);
}
NotificationManager.error('unknown server error', err);
return next(err);
}
示例7: function
Editor.dao.find({where: {id: list[index].editorid}}, function (err, editors) {
list[index].editor = editors[0];
asyncToDo--;
if (asyncToDo === 0) {
data.info.confirmation = books.length + " books found.";
data.book = req.query;
if (req.baseUrl === "/api") {
res.json(data);
return;
}
if (req.xhr) {
res.send(data);
} else {
res.render("book/search", {
data
});
}
}
});
示例8: updatePhrase
public async updatePhrase (req: Request, res: Response): Promise<void> {
let success = false;
let error = "";
const phrase = this.getPhraseFromBody(req.body);
if (this.m_phraseHandler.isEntityValid(phrase, true)) {
success = await this.m_phraseHandler.update(phrase);
if (!success) {
error = "Failed to update the phrase in database.";
}
}
else {
error = "Invalid phrase.";
}
res.json({
success: success,
error: error
});
}
示例9: create
public async create (req: Request, res: Response): Promise<void> {
let category: Category = this.getCategoryFromBody(req.body);
let error = "";
if (this.m_categoryHandler.isEntityValid(category, false)) {
const success = await this.m_categoryHandler.add(category);
if (!success) {
category = null;
error = "Failed to add the category to database.";
}
}
else {
category = null;
error = "Invalid category.";
}
res.json({
category: category,
error: error
});
}
示例10:
}).then(subject => {
// locations populated
for (let user of subject.users) {
// Remap fields
user.firstname = user.user.firstname;
user.lastname = user.user.lastname;
user._id = user.user._id;
// remove unnecessary fields
if (user.role !== "Student" || !showTasks) {
delete user.tasks;
}
delete user.__v;
delete user.user;
delete user.subject;
}
// Send subject
res.json(subject);
}, (err) => {