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

new changes #1190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#DATABASE = "mongodb://localhost:27017"
#RESEND_API = "your resend_api"
DATABASE = "mongodb+srv://192105adityashah:[email protected]/testdel?retryWrites=true&w=majority&appName=Cluster0"
RESEND_API = "re_ZB3uVo4u_DUGNmBHzp22NQXG8GUhE2jA7"
#OPENAI_API_KEY = "your open_ai api key"
JWT_SECRET= "your_private_jwt_secret_key"
NODE_ENV = "production"
Expand Down
15 changes: 15 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:20.9.0-alpine

WORKDIR /usr/src/app

RUN npm install -g [email protected]

COPY package*.json ./

COPY . .

RUN npm install

EXPOSE 8888

CMD ["npm", "run", "dev"]
109 changes: 105 additions & 4 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "idurar-erp-crm",
"version": "4.1.0",
"version": "4.0.0",
"engines": {
"npm": "10.2.4",
"node": "20.9.0"
Expand All @@ -23,7 +23,7 @@
"dotenv": "16.3.1",
"express": "^4.18.2",
"express-fileupload": "^1.4.3",
"express-rate-limit": "^7.1.5",
"express-rate-limit": "^7.4.1",
"glob": "10.3.10",
"html-pdf": "^3.0.1",
"joi": "^17.11.0",
Expand All @@ -37,6 +37,9 @@
"node-cache": "^5.1.2",
"openai": "^4.27.0",
"pug": "^3.0.2",
"rate-limit-redis": "^4.2.0",
"redis": "^4.7.0",
"request-ip": "^3.3.0",
"resend": "^2.0.0",
"shortid": "^2.2.16",
"transliteration": "^2.3.5"
Expand Down
91 changes: 91 additions & 0 deletions backend/src/controllers/appControllers/clientController/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const mongoose = require('mongoose');

const People = mongoose.model('People');
const Company = mongoose.model('Company');

const create = async (Model, req, res) => {
// Creating a new document in the collection

if (req.body.type === 'people') {
if (!req.body.people) {
return res.status(403).json({
success: false,
message: 'Please select a people',
});
} else {
let client = await Model.findOne({
people: req.body.people,
removed: false,
});

if (client) {
return res.status(403).json({
success: false,
result: null,
message: 'Client Already Exist',
});
}

let { firstname, lastname } = await People.findOneAndUpdate(
{
_id: req.body.people,
removed: false,
},
{ isClient: true },
{
new: true, // return the new result instead of the old one
runValidators: true,
}
).exec();
req.body.name = firstname + ' ' + lastname;
req.body.company = undefined;
}
} else {
if (!req.body.company) {
return res.status(403).json({
success: false,
message: 'Please select a company',
});
} else {
let client = await Model.findOne({
company: req.body.company,
removed: false,
});

if (client) {
return res.status(403).json({
success: false,
result: null,
message: 'Client Already Exist',
});
}
let { name } = await Company.findOneAndUpdate(
{
_id: req.body.company,
removed: false,
},
{ isClient: true },
{
new: true, // return the new result instead of the old one
runValidators: true,
}
).exec();
req.body.name = name;
req.body.people = undefined;
}
}

req.body.removed = false;
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 ',
});
};

module.exports = create;
17 changes: 16 additions & 1 deletion backend/src/controllers/appControllers/clientController/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
const mongoose = require('mongoose');
const createCRUDController = require('@/controllers/middlewaresControllers/createCRUDController');

const remove = require('./remove');
const summary = require('./summary');

const create = require('./create');
const read = require('./read');
const search = require('./search');
const update = require('./update');

const listAll = require('./listAll');
const paginatedList = require('./paginatedList');

function modelController() {
const Model = mongoose.model('Client');
const methods = createCRUDController('Client');

methods.read = (req, res) => read(Model, req, res);
methods.delete = (req, res) => remove(Model, req, res);
methods.list = (req, res) => paginatedList(Model, req, res);
methods.summary = (req, res) => summary(Model, req, res);
methods.create = (req, res) => create(Model, req, res);
methods.update = (req, res) => update(Model, req, res);
methods.search = (req, res) => search(Model, req, res);
methods.listAll = (req, res) => listAll(Model, req, res);
return methods;
}

Expand Down
30 changes: 30 additions & 0 deletions backend/src/controllers/appControllers/clientController/listAll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { migrate } = require('./migrate');

const listAll = async (Model, req, res) => {
const sort = parseInt(req.query.sort) || 'desc';

// Query the database for a list of all results
const result = await Model.find({
removed: false,
})
.sort({ created: sort })
.populate()
.exec();

const migratedData = result.map((x) => migrate(x));
if (result.length > 0) {
return res.status(200).json({
success: true,
result: migratedData,
message: 'Successfully found all documents',
});
} else {
return res.status(203).json({
success: true,
result: [],
message: 'Collection is Empty',
});
}
};

module.exports = listAll;
16 changes: 16 additions & 0 deletions backend/src/controllers/appControllers/clientController/migrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exports.migrate = (result) => {
const client = result.type === 'people' ? result.people : result.company;
let newData = {};
newData._id = result._id;
newData.type = result.type;
newData.name = result.name;
newData.phone = client.phone;
newData.email = client.email;
newData.website = client.website;
newData.country = client.country;
newData.address = client.address;
newData.people = result.people;
newData.company = result.company;
newData.notes = result.notes;
return newData;
};
Loading
Loading