Skip to content
Merged
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
36 changes: 0 additions & 36 deletions .eslintrc.cjs

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "always",
"printWidth": 150
}
7 changes: 0 additions & 7 deletions .prettierrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import configHelper from '../lib/helpers/config.js';

const initGlobalConfig = async () => {
// Get the current config
const _path = path.join(process.cwd(), './config', 'defaults', `${process.env.NODE_ENV}.js` || 'development.js');
const _path = path.join(process.cwd(), './config', 'defaults', `${process.env.NODE_ENV || 'development'}.js`);
let defaultConfig;
if (fs.existsSync(`${_path}`)) defaultConfig = await import(_path);
else {
Expand Down
41 changes: 41 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import js from '@eslint/js';
import prettier from 'eslint-config-prettier';
import globals from 'globals';

export default [
js.configs.recommended,
prettier,
{
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: {
...globals.node,
...globals.es2022,
},
},
rules: {
'no-console': 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'max-len': 'off',
'no-param-reassign': 'off',
'prefer-destructuring': ['error', { object: false, array: false }],
'consistent-return': 'off',
'no-underscore-dangle': 'off',
'no-shadow': 'off',
'operator-linebreak': 'off',
'no-unused-vars': ['error', { caughtErrors: 'none' }],
'no-useless-assignment': 'off',
'preserve-caught-error': 'off',
'no-unassigned-vars': 'off',
},
},
{
files: ['**/*.tests.js'],
languageOptions: {
globals: {
...globals.jest,
},
},
},
];
2 changes: 1 addition & 1 deletion lib/helpers/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const getUniqueMessage = (err) => {
}
const fieldName = err.errmsg.substring(begin, err.errmsg.lastIndexOf('_1'));
output = `${fieldName.charAt(0).toUpperCase() + fieldName.slice(1)} already exists`;
} catch (err) {
} catch (_err) {
output = 'Unique field already exists';
}

Expand Down
6 changes: 3 additions & 3 deletions lib/services/express.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-restricted-syntax */
/* eslint-disable no-await-in-loop */
/**
* Module dependencies.
*/
Expand Down Expand Up @@ -156,7 +156,7 @@ const initModulesServerRoutes = async (app) => {
const route = await import(path.resolve(routePath));
route.default(app);
}
app.get('*', (req, res) => {
app.get('/{*path}', (req, res) => {
res.send('<center><br /><h1>Devkit Node Api</h1><h3>Available on <a href="/api/tasks">/api</a>. #LetsGetTogether</h3></center>');
});
};
Expand Down
2 changes: 1 addition & 1 deletion lib/services/gridfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class GridFsStorage {
const metadata = {
user: req.user.id ? new mongoose.Types.ObjectId(req.user.id) : null,
kind: req.kind ? req.kind : null,
contentType: file.mimetype,
};
const filename = `${crypto.randomBytes(32).toString('hex')}${path.extname(file.originalname)}`;
const options = {
metadata,
contentType: file.mimetype,
};

const uploadStream = this.bucket.openUploadStreamWithId(new mongoose.Types.ObjectId(), filename, options);
Expand Down
2 changes: 1 addition & 1 deletion modules/auth/config/strategies/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default () => {
return done(null, false, {
message: 'Invalid email or password',
});
} catch (err) {
} catch (_err) {
return done();
}
},
Expand Down
4 changes: 2 additions & 2 deletions modules/auth/config/users.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
/**
* Module dependencies
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/auth/controllers/auth.password.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const validateResetToken = async (req, res) => {
const user = await UserService.getBrut({ resetPasswordToken: req.params.token });
if (!user || !user.email) return res.redirect('/api/password/reset/invalid');
res.redirect(`/api/password/reset/${req.params.token}`);
} catch (err) {
} catch (_err) {
return res.redirect('/api/password/reset/invalid');
}
};
Expand Down
8 changes: 5 additions & 3 deletions modules/uploads/controllers/uploads.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ const get = async (req, res) => {
stream.on('error', (err) => {
responses.error(res, 422, 'Unprocessable Entity', errors.getMessage(err))(err);
});
res.set('Content-Type', req.upload.contentType);
res.set('Content-Length', req.upload.length);
const contentType = req.upload.contentType || req.upload.metadata?.contentType || 'application/octet-stream';
res.set('Content-Type', contentType);
if (req.upload.length) res.set('Content-Length', req.upload.length);
stream.pipe(res);
} catch (err) {
responses.error(res, 422, 'Unprocessable Entity', errors.getMessage(err))(err);
Expand All @@ -41,7 +42,8 @@ const getSharp = async (req, res) => {
stream.on('error', (err) => {
responses.error(res, 422, 'Unprocessable Entity', errors.getMessage(err))(err);
});
res.set('Content-Type', req.upload.contentType);
const contentType = req.upload.contentType || req.upload.metadata?.contentType || 'application/octet-stream';
res.set('Content-Type', contentType);
switch (req.sharpOption) {
case 'blur':
stream.pipe(sharp().resize(req.sharpSize).blur(config.uploads.sharp.blur)).pipe(res);
Expand Down
8 changes: 4 additions & 4 deletions modules/uploads/repositories/uploads.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ const remove = async (upload) => {
const deleteMany = async (filter) => {
const uploads = await list(filter);
let deletedCount = 0;
// eslint-disable-next-line no-restricted-syntax
for (const upload of uploads) {
try {
// eslint-disable-next-line no-await-in-loop
await bucket.delete(upload._id);
deletedCount += 1;
} catch (err) {
Expand Down Expand Up @@ -103,10 +103,10 @@ const purge = async (kind, collection, key) => {
{ $match: { references: [] } },
]);
let deletedCount = 0;
// eslint-disable-next-line no-restricted-syntax
for (const upload of toDelete) {
try {
// eslint-disable-next-line no-await-in-loop
await bucket.delete(upload._id);
deletedCount += 1;
} catch (err) {
Expand Down
Loading
Loading