mirror of
				https://github.com/xfarrow/blink
				synced 2025-06-27 09:03:02 +02:00 
			
		
		
		
	create org post
This commit is contained in:
		| @@ -22,6 +22,7 @@ app.post('/blinkapi/login', api_controller.login); // Login | |||||||
| app.get('/blinkapi/person/:id', api_controller.verifyToken, api_controller.getPerson); // Obtain Person's details | app.get('/blinkapi/person/:id', api_controller.verifyToken, api_controller.getPerson); // Obtain Person's details | ||||||
| app.post('/blinkapi/organization', api_controller.verifyToken, api_controller.createOrganization); // Create organization | app.post('/blinkapi/organization', api_controller.verifyToken, api_controller.createOrganization); // Create organization | ||||||
| app.delete('/blinkapi/organization/:id', api_controller.verifyToken, api_controller.deleteOrganization); // Delete organization | app.delete('/blinkapi/organization/:id', api_controller.verifyToken, api_controller.deleteOrganization); // Delete organization | ||||||
|  | app.post('/blinkapi/organization/post', api_controller.verifyToken, api_controller.createOrganizationPost); // Create a organization's post | ||||||
|  |  | ||||||
| // Start the server | // Start the server | ||||||
| app.listen(process.env.API_SERVER_PORT, () => { | app.listen(process.env.API_SERVER_PORT, () => { | ||||||
|   | |||||||
| @@ -188,6 +188,34 @@ async function deleteOrganization(req, res){ | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // POST | ||||||
|  | async function createOrganizationPost(req, res){ | ||||||
|  |   const organizationPostData = req.body; | ||||||
|  |    | ||||||
|  |   // Ensure that the required fields are present before proceeding | ||||||
|  |   if (!organizationPostData.organization_id || !organizationPostData.content) { | ||||||
|  |     return res.status(400).json("Invalid request."); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   try { | ||||||
|  |     if (await isPersonOrganizationAdmin(req.jwt.person_id, organizationPostData.organization_id)){ | ||||||
|  |       const organizationPost = await db.one('INSERT INTO "OrganizationPost" (organization_id, content) VALUES ($1, $2) RETURNING *',  | ||||||
|  |                                             [organizationPostData.organization_id, organizationPostData.content]); | ||||||
|  |       if(organizationPost){ | ||||||
|  |         return res.status(200).json(organizationPost); | ||||||
|  |       } | ||||||
|  |       else{ | ||||||
|  |         return res.status(500).json("Internal server error"); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     else{ | ||||||
|  |       return res.status(401).json("Forbidden"); | ||||||
|  |     } | ||||||
|  |   } catch (error) { | ||||||
|  |     return res.status(500).json("Internal server error"); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| // ======== END API ENDPOINTS ======== | // ======== END API ENDPOINTS ======== | ||||||
|  |  | ||||||
| async function checkUserCredentials(email, password){ | async function checkUserCredentials(email, password){ | ||||||
| @@ -256,5 +284,6 @@ module.exports = { | |||||||
|     getPerson, |     getPerson, | ||||||
|     verifyToken, |     verifyToken, | ||||||
|     createOrganization, |     createOrganization, | ||||||
|     deleteOrganization |     deleteOrganization, | ||||||
|  |     createOrganizationPost | ||||||
| }; | }; | ||||||
		Reference in New Issue
	
	Block a user