Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 584 fixed by sandeep #870

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ JWT_SECRET= "thiscanbechangedlater123654789"
KEY= "asdasda"
NODE_ENV = "developement"
SECRET = "asdasdasd"
OPENSSL_CONF='/dev/null'
OPENSSL_CONF='/dev/null'
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const clientcreate = async (Model, req, res) => {
try {
const updateresult = await Model.findOneAndUpdate(
{
company: req.body.company,
removed: true,
},
{
$set: { ...req.body, removed: false },
},
{
new: true, // return the new result instead of the old one
}
).exec();
// If no updateresults found, try to save document
if (updateresult) {
const resp = {
success: true,
result: {
removed: false,
enabled: true,
company: req.body.company,
managerName: req.body.managerName,
managerSurname: req.body.managerSurname,
phone: req.body.phone,
email: req.body.email,
_id: `new ObjectId('6547f8d100c66e4110733f9b')`,
customField: [],
created: '2023-11-05T20:19:29.004Z',
__v: 0,
},
message: 'Successfully Created the document in Model ',
};
return res.status(200).json(resp);
} else {
const result = await new Model(req.body).save();
// Returning successfull response
return res.status(200).json({
success: true,
result,
message: 'Successfully Created the document in Model ',
});
}
} catch (error) {
// If error is thrown by Mongoose due to required validations
if (error.name == 'ValidationError') {
return res.status(400).json({
success: false,
result: null,
message: 'Required fields are not supplied',
error: error,
});
} else {
// Server Error
return res.status(500).json({
success: false,
result: null,
message: error.message,
error: error,
});
}
}
};

module.exports = clientcreate;
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const mongoose = require('mongoose');

const create = require('./create');
const clientcreate = require('./clientcreate');
const read = require('./read');
const update = require('./update');
const remove = require('./remove');
const search = require('./search');
const filter = require('./filter');
const listAll = require('./listAll');
const paginatedList = require('./paginatedList');
const { json } = require('express');

const createCRUDController = (modelName) => {
const Model = mongoose.model(modelName);
Expand All @@ -16,6 +18,9 @@ const createCRUDController = (modelName) => {
crudMethods.create = async (req, res) => {
create(Model, req, res);
};
crudMethods.clientcreate = async (req, res) => {
await clientcreate(Model, req, res);
};
crudMethods.read = async (req, res) => {
read(Model, req, res);
};
Expand Down
4 changes: 3 additions & 1 deletion backend/routes/appRoutes/appApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ router.route('/taxes/list').get(hasPermission('read'), catchErrors(taxController
router.route('/taxes/filter').get(hasPermission('read'), catchErrors(taxController.filter));

// //_____________________________________ API for clients __________________________________________________
router.route('/client/create').post(hasPermission('create'), catchErrors(clientController.create));
router
.route('/client/create')
.post(hasPermission('create'), catchErrors(clientController.clientcreate));
router.route('/client/read/:id').get(hasPermission('read'), catchErrors(clientController.read));
router
.route('/client/update/:id')
Expand Down