[Route] PATCH /guilds/:id/templates
This commit is contained in:
		
							parent
							
								
									aeafd30b01
								
							
						
					
					
						commit
						be50cc3d35
					
				| @ -1,7 +1,7 @@ | |||||||
| import { Request, Response, Router } from "express"; | import { Request, Response, Router } from "express"; | ||||||
| import { TemplateModel, GuildModel, getPermission, toObject, UserModel } from "@fosscord/server-util"; | import { TemplateModel, GuildModel, getPermission, toObject, UserModel } from "@fosscord/server-util"; | ||||||
| import { HTTPError } from "lambert-server"; | import { HTTPError } from "lambert-server"; | ||||||
| import { TemplateCreateSchema } from "../../../schema/Template"; | import { TemplateCreateSchema, TemplateModifySchema } from "../../../schema/Template"; | ||||||
| import { emitEvent } from "../../../util/Event"; | import { emitEvent } from "../../../util/Event"; | ||||||
| import { check } from "../../../util/instanceOf"; | import { check } from "../../../util/instanceOf"; | ||||||
| import { getPublicUser } from "../../../util/User"; | import { getPublicUser } from "../../../util/User"; | ||||||
| @ -103,4 +103,31 @@ router.put("/:template_id", async (req: Request, res: Response) => { | |||||||
| 	res.json(toObject(templateobj)).send(); | 	res.json(toObject(templateobj)).send(); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | router.patch("/:template_id", check(TemplateModifySchema), async (req: Request, res: Response) => { | ||||||
|  |     const guild_id = req.params.guild_id; | ||||||
|  |     const { template_id } = req.params; | ||||||
|  | 
 | ||||||
|  | 	const guild = await GuildModel.findOne({ id: guild_id }, { id: true }).exec(); | ||||||
|  | 	if (!guild) throw new HTTPError("Guild not found", 404); | ||||||
|  | 	if (!template_id) throw new HTTPError("Unknown template_id", 404); | ||||||
|  | 
 | ||||||
|  | 	const user = await UserModel.findOne({ id: req.user_id }).exec(); | ||||||
|  | 	if (!user) throw new HTTPError("User not found", 404); | ||||||
|  | 
 | ||||||
|  | 	const template = await TemplateModel.findById({ _id: template_id }).exec(); | ||||||
|  | 	if (!template) throw new HTTPError("template not found", 404); | ||||||
|  | 
 | ||||||
|  | 	/*const perms = await getPermission(req.user_id, guild_id); | ||||||
|  | 
 | ||||||
|  | 	if (!perms.has("MANAGE_GUILD")) | ||||||
|  | 		throw new HTTPError("You missing the MANAGE_GUILD permission", 401);*/ | ||||||
|  | 
 | ||||||
|  | 	var templateobj = await TemplateModel.findByIdAndUpdate({ | ||||||
|  | 		_id: template_id | ||||||
|  | 	}, {name: req.body.name, | ||||||
|  | 		description: req.body.description || "No description"}).exec(); | ||||||
|  | 
 | ||||||
|  | 	res.json(toObject(templateobj)).send(); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
| export default router; | export default router; | ||||||
|  | |||||||
| @ -8,3 +8,14 @@ export interface TemplateCreateSchema { | |||||||
| 	name: string, | 	name: string, | ||||||
| 	description?: string, | 	description?: string, | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | export const TemplateModifySchema = { | ||||||
|  | 	name: String, | ||||||
|  | 	$description: String, | ||||||
|  | 
 | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export interface TemplateModifySchema { | ||||||
|  | 	name: string, | ||||||
|  | 	description?: string, | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user