Update welcome_screen.ts
This commit is contained in:
		
							parent
							
								
									1ee6d29c64
								
							
						
					
					
						commit
						462c40521a
					
				| @ -17,5 +17,29 @@ router.get("/", async (req: Request, res: Response) => { | |||||||
| 	res.json(toObject(guild.welcome_screen)); | 	res.json(toObject(guild.welcome_screen)); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | router.post("/", check(GuildAddChannelToWelcomeScreenSchema), async (req: Request, res: Response) => { | ||||||
|  | 	const guild_id = req.params.id; | ||||||
|  | 	const body = req.body as GuildAddChannelToWelcomeScreenSchema; | ||||||
|  | 
 | ||||||
|  | 	const guild = await GuildModel.findOne({ id: guild_id }).exec(); | ||||||
|  | 	if (!guild) throw new HTTPError("Guild not found", 404); | ||||||
|  | 
 | ||||||
|  | 	var channelObject = { | ||||||
|  | 		...body | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if(guild.welcome_screen.welcome_channels.some(channel => channel.channel_id === body.channel_id)){ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	await GuildModel.findOneAndUpdate( | ||||||
|  | 		{ | ||||||
|  | 			id: guild_id, | ||||||
|  | 		}, | ||||||
|  | 		{ $push: { "welcome_screen.welcome_channels": channelObject } } | ||||||
|  | 	).exec(); | ||||||
|  | 
 | ||||||
|  | 	res.json(toObject(guild.welcome_screen)); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| export default router; | export default router; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Intevel ツ
						Intevel ツ