Skip to content
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
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/migration-script/**
src/jobs/user-migration/**
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ module.exports = {
],
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
"radix": "error",
"semi": "error",
"semi": "off",
"keyword-spacing": ["error", { "after": true, "before": true }],
"space-before-blocks": ["error", { "functions": "always", "keywords": "always", "classes": "always" }],
"space-before-function-paren": [
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
min-release-age=7
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24.15.0
4,741 changes: 2,520 additions & 2,221 deletions package-lock.json

Large diffs are not rendered by default.

49 changes: 25 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "prescription-validator-api",
"version": "1.0.0",
"description": "NodeJS + MongoDB API for Prescription Management",
"engines": {
"node": "24.x"
},
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -28,18 +31,18 @@
"axios": "^0.27.2",
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.2",
"compression": "^1.7.4",
"compression": "^1.8.1",
"concurrently": "^5.3.0",
"cors": "^2.8.5",
"cors": "^2.8.6",
"dotenv": "^8.6.0",
"express": "^4.17.1",
"express": "^4.22.1",
"fast-csv": "^4.3.6",
"handlebars": "^4.7.8",
"helmet": "^3.21.2",
"helmet": "^3.23.3",
"jsonwebtoken": "^8.5.1",
"moment": "^2.30.1",
"mongodb": "^3.2.7",
"mongoose": "^5.6.9",
"mongodb": "^3.7.4",
"mongoose": "^5.13.23",
"morgan": "^1.9.1",
"needle": "^2.9.1",
"nodemailer": "^6.9.14",
Expand All @@ -52,29 +55,27 @@
},
"devDependencies": {
"@types/agenda": "^2.0.9",
"@types/bcryptjs": "^2.4.2",
"@types/compression": "^1.7.0",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.2",
"@types/bcryptjs": "^2.4.6",
"@types/compression": "^1.8.1",
"@types/cors": "^2.8.19",
"@types/express": "^4.17.21",
"@types/helmet": "0.0.45",
"@types/jsonwebtoken": "^8.3.8",
"@types/mongoose": "^5.7.8",
"@types/morgan": "^1.9.0",
"@types/jsonwebtoken": "^8.5.9",
"@types/mongoose": "^5.11.96",
"@types/morgan": "^1.9.10",
"@types/needle": "^2.5.3",
"@types/node": "^13.13.52",
"@types/passport": "^1.0.3",
"@types/passport-jwt": "^3.0.3",
"@types/passport-local": "^1.0.33",
"@types/node": "^24.12.4",
"@types/passport": "^1.0.17",
"@types/passport-jwt": "^3.0.13",
"@types/passport-local": "^1.0.38",
"@types/uuid": "^7.0.3",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/eslint-plugin-tslint": "^4.29.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.57.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prefer-arrow": "^1.2.3",
"nodemon": "^3.1.4",
"ts-node": "^8.10.2",
"tslint-eslint-rules": "^4.1.1",
"typescript": "^3.9.10"
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}
18 changes: 9 additions & 9 deletions src/common/http-exception.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export default class HttpException extends Error {
statusCode: number;
message: string;
error: string | null;
statusCode: number;
message: string;
error: string | null;

constructor(statusCode: number, message: string, error?: string) {
super(message);
constructor(statusCode: number, message: string, error?: string) {
super(message);

this.statusCode = statusCode;
this.message = message;
this.error = error || null;
}
this.statusCode = statusCode;
this.message = message;
this.error = error || null;
}
}
2 changes: 1 addition & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export const httpCodes = {
INTERNAL_SERVER_ERROR: 500,
OK: 200,
NOT_FOUND: 404,
};
};
1,023 changes: 520 additions & 503 deletions src/controllers/auth.controller.ts

Large diffs are not rendered by default.

41 changes: 21 additions & 20 deletions src/controllers/certificate.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BaseController } from '../interfaces/classes/base-controllers.interface
import ICertificate from '../interfaces/certificate.interface';
import Certificate from '../models/certificate.model';
import IPatient from '../interfaces/patient.interface';
import Patient from '../models/patient.model';
import { findOrCreatePatient } from '../models/patient.model';
import IUser from '../interfaces/user.interface';
import User from '../models/user.model';

Expand All @@ -12,11 +12,11 @@ class CertificateController implements BaseController {
public index = async (req: Request, res: Response): Promise<Response> => {
const certificates: ICertificate[] = await Certificate.find();
return res.status(200).json({ certificates });
}
};

public create = async (req: Request, res: Response): Promise<Response> => {
const { professional, patient, certificate, startDate, cantDias } = req.body;
const myPatient: IPatient = await Patient.schema.methods.findOrCreate(patient);
const myPatient: IPatient = await findOrCreatePatient(patient);
const myProfessional: IUser | null = await User.findOne({ _id: professional });
try {
const newCertificate = new Certificate({
Expand All @@ -41,7 +41,7 @@ class CertificateController implements BaseController {
} catch (error) {
return res.status(500).json('Error al cargar el certificado');
}
}
};

public update = async (req: Request, res: Response): Promise<Response> => {
const { id } = req.params;
Expand All @@ -60,20 +60,20 @@ class CertificateController implements BaseController {
} catch (error) {
return res.status(500).json('Server Error');
}
}
};

public getByUserId = async (req: Request, res: Response): Promise<Response> => {
try {
const { id } = req.params;
const { offset = 0, limit = 10 } = req.query;

const certificates: ICertificate[] | null = await Certificate.find({ 'professional.userId': id })
.sort({ startDate: -1 })
.skip(Number(offset))
.limit(Number(limit));

const total = await Certificate.countDocuments({ 'professional.userId': id });

return res.status(200).json({
certificates,
total,
Expand All @@ -83,18 +83,18 @@ class CertificateController implements BaseController {
} catch (err) {
return res.status(500).json('Server Error');
}
}
};

public searchByTerm = async (req: Request, res: Response): Promise<Response> => {
try {
const { id } = req.params; // professional userId
const { searchTerm } = req.query;
const { offset = 0, limit = 10 } = req.query;

if (!searchTerm) {
return res.status(400).json('Término de búsqueda requerido');
}

// Crear query para buscar por DNI o nombre del paciente
const searchQuery = {
'professional.userId': id,
Expand All @@ -105,14 +105,14 @@ class CertificateController implements BaseController {
{ 'patient.nombreAutopercibido': { $regex: searchTerm, $options: 'i' } }
]
};

const certificates: ICertificate[] | null = await Certificate.find(searchQuery)
.sort({ createdAt: -1 })
.skip(Number(offset))
.limit(Number(limit));

const total = await Certificate.countDocuments(searchQuery);

return res.status(200).json({
certificates,
total,
Expand All @@ -122,15 +122,15 @@ class CertificateController implements BaseController {
} catch (err) {
return res.status(500).json('Server Error');
}
}
};
public show = async (req: Request, res: Response): Promise<Response> => {
// Implementation for showing a certificate by ID
// const certificate = await Certificate.findById(req.params.id);
// if (!certificate) {
// return res.status(404).json({ message: 'Certificate not found' });
// }
return res.status(201);
}
};


public delete = async (req: Request, res: Response): Promise<Response> => {
Expand All @@ -140,7 +140,7 @@ class CertificateController implements BaseController {
// }
// return res.status(200).json({ message: 'Certificate deleted successfully' });
return res.status(201);
}
};

public getById = async (req: Request, res: Response): Promise<Response> => {
try {
Expand All @@ -149,11 +149,12 @@ class CertificateController implements BaseController {

return res.status(200).json(certificate);
} catch (err) {
// eslint-disable-next-line no-console
console.log(err);
return res.status(500).json('Server Error');
}
}
};

}

export default new CertificateController();
export default new CertificateController();
2 changes: 1 addition & 1 deletion src/controllers/jobs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class JobsController {
data: { when }
});
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error programando envio de recetas:', error);
return res.status(500).json({
success: false,
Expand Down Expand Up @@ -221,7 +222,6 @@ class JobsController {
public deleteJobs = async (req: Request, res: Response): Promise<Response> => {
try {
const { jobIds } = req.body;
console.log('Request to delete jobs with IDs:', jobIds);

if (!jobIds && !jobIds.length) {
return res.status(400).json({
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/patient.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class PatientController implements BaseController {
if (typeof req.body.firstName !== 'undefined') { values.firstName = req.body.firstName; }
if (typeof req.body.sex !== 'undefined') { values.sex = req.body.sex; }
const opts: any = { runValidators: true, new: true, context: 'query' };
const patient: IPatient | null = await Patient.findOneAndUpdate({ _id: id }, values, opts).select('dni lastName firstName sex');
await Patient.updateOne({ _id: id }, values, opts);
const patient: IPatient | null = await Patient.findById(id).select('dni lastName firstName sex');

return res.status(200).json(patient);
} catch (e) {
Expand Down
Loading
Loading