Skip to content

Commit

Permalink
Merge pull request #32 from deevanshu-k/property_route_publish
Browse files Browse the repository at this point in the history
Property route publish
  • Loading branch information
deevanshu-k authored Dec 18, 2023
2 parents 71c47f7 + b62459c commit 17ea232
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
31 changes: 30 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,33 @@
- LANDLORD: update rooms (details + image) (only updating details are passed)
- LANDLORD: delete rooms
- LANDLORD: get rooms
- TENANT: get rooms (based on plan)
- TENANT: get rooms (based on plan)
3) Landlord:
- publishProperty-Des-if(count(p-published) > n) (PATCH #21)
4) Admin:
- Get all landlords **DONE**
- Get all tenants **DONE**
- Get all properties after (PATCH #21) **DONE**
- Update profile photo
- Get landlord documents **DONE**
- Get tenant documents **DONE**
- Verify Landlord ( Also mail integration ) **DONE**
- Verify Tenant ( Also mail integration ) **DONE**
- Verify Property ( Also mail integration ) **DONE**
- UnVerify landlord ( Also mail integration ) **DONE**
- UnVerify tenant ( Also mail integration ) **DONE**
- UnVerify property ( Also mail integration ) **DONE**
- Delete tenant ( Also mail integration )
- Delete landlord ( Also mail integration )
- Delete property ( Also mail integration )
- Get server logs ( **Main--Security** )
- Get server health ( **Main--Security** )
60 changes: 59 additions & 1 deletion controllers/property.ctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let property = {};
} object
*/


/* Landlord Controllers */
property.getAllProperties = async (req, res) => {
try {
// Return all properties of landlord ID (req.user.id) provided
Expand Down Expand Up @@ -302,6 +302,64 @@ property.getProperty = async (req, res) => {
}
}

property.publishProperty = async (req, res) => {
try {
const user = req.user

// Get propertyId And publish From Query
const { propertyId, publish } = req.query;
if (!propertyId || (publish != 'true' && publish != 'false')) {
return res.status(Constant.BAD_REQUEST).json({
code: Constant.BAD_REQUEST,
message: Constant.REQUEST_BAD_REQUEST,
})
}

// Check If Property Belongs to landlord
const property = await db.property.findOne({ where: { landlordId: req.user.id, id: propertyId } });
if (!property) {
return res.status(Constant.BAD_REQUEST).json({
code: Constant.BAD_REQUEST,
message: Constant.REQUEST_BAD_REQUEST,
})
}

// Check If Landlord Allowed to publish more property
if (publish === 'true') {
const propertyLimit = Constant.PLANS[user.subscription_plan].no_of_property
const countPublishedProperty = await db.property.count({ where: { landlordId: user.id, publish_status: true } });
if (countPublishedProperty >= propertyLimit) { // BUG: What is somehow more than allowed propety already exist
return res.status(Constant.FORBIDDEN_CODE).json({
code: Constant.FORBIDDEN_CODE,
message: Constant.SUBSCRIPTION_PLAN_LIMIT_REACHED
});
}
}

// Update Property Publish Status
await db.property.update({
publish_status: publish
}, {
where: {
id: propertyId,
landlordId: user.id,
verification_status: true
}
});

return res.status(Constant.SUCCESS_CODE).json({
code: Constant.SUCCESS_CODE,
message: Constant.UPDATE_SUCCESS
});

} catch (error) {
return res.status(Constant.SERVER_ERROR).json({
code: Constant.SERVER_ERROR,
message: Constant.SOMETHING_WENT_WRONG,
})
}
}

/* Admin Controllers */
property.adminGetAllProperty = async (req, res) => {
try {
Expand Down
1 change: 1 addition & 0 deletions routes/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ router.put("", rateLimiter.landlordOperationsRouteRateLimiter, auth.checkAuthent
router.post("", rateLimiter.landlordOperationsRouteRateLimiter, auth.checkAuthentication, checkUser.landlord, property.updateProperty);
router.delete("/:propertyId", rateLimiter.landlordOperationsRouteRateLimiter, auth.checkAuthentication, checkUser.landlord, property.deleteProperty);
router.get("/:propertyId", rateLimiter.landlordOperationsRouteRateLimiter, auth.checkAuthentication, checkUser.landlord, property.getProperty);
router.post("/publish", rateLimiter.landlordOperationsRouteRateLimiter, auth.checkAuthentication, checkUser.landlord, property.publishProperty);

module.exports = router;

0 comments on commit 17ea232

Please sign in to comment.