本文整理匯總了TypeScript中express.Router.delete方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Router.delete方法的具體用法?TypeScript Router.delete怎麽用?TypeScript Router.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Router
的用法示例。
在下文中一共展示了Router.delete方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: createRoutes
export function createRoutes(router: Router, auth: RequestHandler, setRouteVar: RequestHandler): void {
// list route
router.get('/', setRouteVar, list)
// single entry route
router.get('/:slug', setRouteVar, get)
// comment route
router.get('/:slug/comments', setRouteVar, comments)
// action list route
router.get('/:slug/:sublist', setRouteVar, sublist)
// check if slug available
router.post('/unique', setRouteVar, isUnique)
// create route
router.post('/', auth, setRouteVar, create)
// create gallery
router.put('/:slug/gallery', auth, setRouteVar, upload)
// clear gallery
router.delete('/:slug/gallery', auth, setRouteVar, clear, update)
// update route
router.patch('/:slug', auth, setRouteVar, update)
// delete route
router.delete('/:slug', auth, setRouteVar, remove)
}
示例2: init
public init() {
this.router.get('/boards', function (req, res) {
board.find({}, function (err, boards) {
res.json(boards);
});
});
this.router.post('/newBoard', function (req, res) {
let newBoard = new board(req.body);
newBoard.save(function (err) {
if (err) {
res.send(err);
}
res.json({
success: true,
message: 'Board created successfully',
});
});
});
this.router.delete('/delete/:id', function (req, res) {
board.findById(req.params.id, (err, responseByID) => {
responseByID.remove(req.body, (err) => {
if (err) {
res.status(500).send(err);
}
board.find((err) => {
if (err) {
res.status(500).send(err)
}
res.json({
success: true,
message: 'Removed!',
});
});
});
});
});
this.router.put('/update/:id', function (req, res) {
board.findById(req.params.id, (err, responseByID) => {
responseByID.update(req.body, (err) => {
if (err) {
res.status(500).send(err);
}
board.find((err) => {
if (err) {
res.status(500).send(err)
}
res.json({
success: true,
message: 'Board update successfully'
});
});
});
});
});
}
示例3: constructor
constructor(){
this.router = Router();
this.controller = new TransactionController();
this.router.get("/:type", (req: Request, res: Response) => this.getTransactions(req, res));
this.router.get("/:type/categories", (req: Request, res: Response) => this.getCategories(req, res));
this.router.post("/transaction", (req: Request, res: Response) => this.postTransaction(req, res));
this.router.post("/", upload.single('file'), (req: Request, res: Response) => this.uploadTransactionsCSV(req, res));
this.router.delete("/:id", (req: Request, res: Response) => this.deleteTransaction(req, res));
}
示例4: mount
mount(router: Router) {
var controller = require(this.controller)
// if there is a target method, check to see if it exists and replace the original controller with it
if (this.target) {
if (!controller.hasOwnProperty(this.target)) {
throw new Error("target function " + this.target + " does not exist on controller " + this.controller)
}
controller = controller[this.target]
}
// if controller is not a function, throw an error
if (typeof (controller) != "function") {
throw new Error("controllers must resolve to a function")
}
// use a switch (rather than checking for the method) to prevent
// unwanted method calls (ie. router.route(this.path, controller) would not be good...)
switch (this.method.toLowerCase()) {
case "all":
router.all(this.path, controller)
break
case "get":
router.get(this.path, controller)
break
case "put":
router.put(this.path, controller)
break
case "post":
router.post(this.path, controller)
break
case "delete":
router.delete(this.path, controller)
break
case "patch":
router.patch(this.path, controller)
break
case "use":
if (typeof this.path === "string") {
router.use(this.path, controller);
} else {
router.use(controller);
}
break;
case "param":
if (typeof this.path === "string") {
router.param(this.path, controller);
} else {
router.param(controller);
}
break;
default:
throw new Error("unsupported method " + this.method)
}
}
示例5: createRoutes
export function createRoutes(router: Router, setRouteVar: RequestHandler, auth: RequestHandler): void {
// list route
router.get('/users', setRouteVar, list)
// route to check unique values
router.post('/users/unique', setRouteVar, isUnique)
// create route
router.post('/users', setRouteVar, create)
// TOTP login route - create
router.post('/login/totp', setRouteVar, initTotp, sendTotp)
// TOTP login route - login/signup
router.patch('/login/totp', setRouteVar, verifyTotp, login)
// reset password routes via TOTP
router.patch('/login/reset', setRouteVar, verifyPasswords, verifyTotp)
// update routes via TOTP
router.patch('/self/totp', setRouteVar, auth, verifyTotp)
// login routes via username/passport
router.post('/login/local', setRouteVar, local, login)
// JWT login routes
router.get('/self', auth, login)
// sublist route
router.get('/self/:sublist', auth, sublist)
// user created content route
router.get('/self/:sublist/:slug', auth, content)
// update route
router.patch('/self', auth, update)
// update user avatar
router.put('/self/avatar', setRouteVar, auth, avatar)
// delete route
router.delete('/self', auth, remove)
// user submit content route
router.post('/self/submit', auth, submit)
// user retract content route
router.post('/self/retract', auth, retract)
}
示例6: registerRoute
function registerRoute(route: RouteRegistration, router: Router, routeUrl: string) {
switch (route.method) {
case RouteMethod.Get:
router.get(routeUrl, (route.descriptor.value as any));
break;
case RouteMethod.Put:
router.put(routeUrl, (route.descriptor.value as any));
break;
case RouteMethod.Post:
router.post(routeUrl, (route.descriptor.value as any));
break;
case RouteMethod.Delete:
router.delete(routeUrl, (route.descriptor.value as any));
break;
case RouteMethod.Head:
router.head(routeUrl, (route.descriptor.value as any));
break;
default:
throw new HttpVerbNotSupportedError(route.method);
}
}
示例7: require
import { Router } from 'express';
var authenticatedPolicy = require("../../policies/authenticated");
import { CollaboratorController } from "../../../app/controllers/collaborator/collaborator.controller";
export const COLLABORATOR_MAIN_ROUTER: Router = Router();
// define routes
//create
COLLABORATOR_MAIN_ROUTER.post('/', CollaboratorController.create);
//getById
COLLABORATOR_MAIN_ROUTER.get('/:id', authenticatedPolicy, CollaboratorController.getById);
//getAll
COLLABORATOR_MAIN_ROUTER.post('/getAll', CollaboratorController.getAll);
//update
COLLABORATOR_MAIN_ROUTER.put('/:id', authenticatedPolicy, CollaboratorController.updateById);
//delete
COLLABORATOR_MAIN_ROUTER.delete('/:id', authenticatedPolicy, CollaboratorController.deleteById);
示例8:
})
})
UsersRouter.get("/:id", (request: Request, response: Response, next: NextFunction) => {
User.findById(request.params.id, (err: any, user: IUser) => {
if (err) return next(err)
response.json(user)
})
})
UsersRouter.put("/:id", (request: Request, response: Response, next: NextFunction) => {
User.findById(request.params.id, (err: any, user: IUser) => {
if (err) return next(err)
request.body.forEach((property: any) => {
user[property] = request.body[property]
});
user.save((err: any, user: IUser) => {
if (err) return next(err)
response.json(user)
})
})
})
UsersRouter.delete("/:id", (request: Request, response: Response, next: NextFunction) => {
User.findByIdAndRemove(request.params.id, (err: any, user: IUser) => {
if (err) return next(err)
response.json({})
})
})
export { UsersRouter }
示例9: delete
delete(targetPath: string, callback: (req: Request, res: Response) => Promise<any>) {
this.router.delete(targetPath, this.wrap(callback))
}
示例10: getIdeas
let registerIdeaRoutes = (
router: Router,
ideaService: IdeaService,
skillService: SkillService,
tagService: TagService,
techService: TechnologyService) => {
router.get('/ideas', getIdeas);
router.get('/ideas/:id', getIdeaById);
router.post('/ideas', createIdea);
router.put('/ideas/:id', updateIdea);
router.delete('/ideas/:id', deleteIdea)
function getIdeas(req: any, res: any) {
let searchStr = req.query.search;
if (searchStr) {
ideaService.search(searchStr)
.then((results: any) => {
res.json(results || []);
})
.catch((err: any) => {
res.status(500).send(err).end();
});
} else {
ideaService.getMany()
.then((ideas: any) => {
res.json(ideas || []);
})
.catch((err: any) => {
res.status(500).send(err).end();
});
}
}
function getIdeaById(req: any, res: any) {
ideaService.getById(req.params.id)
.then((idea: any) => {
if (idea) {
res.json(idea);
} else {
notFoundSvc.send404(req, res);
}
})
.catch((err: any) => {
res.status(500).send(err).end();
});
}
function createIdea(req: any, res: any) {
//TODO: add location header
ideaService.insert(req.body)
.then((idea: any) => {
if (idea) {
for (let tag of idea.tags) {
tagService.save(tag);
}
for (let skill of idea.skills) {
skillService.save(skill);
}
for (let tech of idea.technologies) {
techService.save(tech);
}
res.status(201).json(idea);
} else {
res.status(500).send('unknown error').end();
}
})
.catch((err: any) => {
res.status(500).send(err).end();
});
}
function updateIdea(req: any, res: any) {
let idea = req.body;
if (req.params.id !== idea._id) {
res.status(400).send('id in payload does not match id in url').end();
}
ideaService.update(idea)
.then((result: any) => {
if (result === true) {
for (let tag of idea.tags) {
tagService.save(tag);
}
for (let skill of idea.skills) {
skillService.save(skill);
}
for (let tech of idea.technologies) {
techService.save(tech);
}
res.status(204).end();
} else {
res.status(500).send('unknown error').end();
}
})
.catch((err: any) => {
res.status(500).send(err).end();
});
}
function deleteIdea(req: any, res: any) {
//.........這裏部分代碼省略.........