diff --git a/client/app/services/user.service.ts b/client/app/services/user.service.ts index 19b409a3..a7a6d4dd 100644 --- a/client/app/services/user.service.ts +++ b/client/app/services/user.service.ts @@ -13,8 +13,8 @@ export class UserService { return this.http.post('/api/user', user); } - login(credentials: { email: string; password: string }): Observable { - return this.http.post('/api/login', credentials); + login(credentials: { email: string; password: string }): Observable<{ token: string }> { + return this.http.post<{ token: string }>('/api/login', credentials); } getUsers(): Observable { @@ -33,11 +33,11 @@ export class UserService { return this.http.get(`/api/user/${user._id}`); } - editUser(user: User): Observable { + editUser(user: User): Observable { return this.http.put(`/api/user/${user._id}`, user, { responseType: 'text' }); } - deleteUser(user: User): Observable { + deleteUser(user: User): Observable { return this.http.delete(`/api/user/${user._id}`, { responseType: 'text' }); } diff --git a/eslint.config.js b/eslint.config.js index 4e5cf13b..eee71051 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -30,8 +30,6 @@ module.exports = tseslint.config( style: "kebab-case", }, ], - "@typescript-eslint/no-explicit-any": "off", - "no-underscore-dangle": "off", "arrow-spacing": "error", "comma-spacing": "error", "indent": ["error", 2], diff --git a/server/controllers/base.ts b/server/controllers/base.ts index 2614bc21..66a99f4c 100644 --- a/server/controllers/base.ts +++ b/server/controllers/base.ts @@ -2,6 +2,7 @@ import { Request, Response } from 'express'; abstract class BaseCtrl { + // eslint-disable-next-line @typescript-eslint/no-explicit-any abstract model: any; // Get all @@ -9,8 +10,8 @@ abstract class BaseCtrl { try { const docs = await this.model.find({}); return res.status(200).json(docs); - } catch (err: any) { - return res.status(400).json({ error: err.message }); + } catch (err) { + return res.status(400).json({ error: (err as Error).message }); } }; @@ -19,8 +20,8 @@ abstract class BaseCtrl { try { const count = await this.model.countDocuments(); return res.status(200).json(count); - } catch (err: any) { - return res.status(400).json({ error: err.message }); + } catch (err) { + return res.status(400).json({ error: (err as Error).message }); } }; @@ -29,8 +30,8 @@ abstract class BaseCtrl { try { const obj = await new this.model(req.body).save(); return res.status(201).json(obj); - } catch (err: any) { - return res.status(400).json({ error: err.message }); + } catch (err) { + return res.status(400).json({ error: (err as Error).message }); } }; @@ -39,8 +40,8 @@ abstract class BaseCtrl { try { const obj = await this.model.findOne({ _id: req.params.id }); return res.status(200).json(obj); - } catch (err: any) { - return res.status(500).json({ error: err.message }); + } catch (err) { + return res.status(500).json({ error: (err as Error).message }); } }; @@ -49,8 +50,8 @@ abstract class BaseCtrl { try { await this.model.findOneAndUpdate({ _id: req.params.id }, req.body); return res.sendStatus(200); - } catch (err: any) { - return res.status(400).json({ error: err.message }); + } catch (err) { + return res.status(400).json({ error: (err as Error).message }); } }; @@ -59,8 +60,8 @@ abstract class BaseCtrl { try { await this.model.findOneAndDelete({ _id: req.params.id }); return res.sendStatus(200); - } catch (err: any) { - return res.status(400).json({ error: err.message }); + } catch (err) { + return res.status(400).json({ error: (err as Error).message }); } }; @@ -69,8 +70,8 @@ abstract class BaseCtrl { try { await this.model.deleteMany(); return res.sendStatus(200); - } catch (err: any) { - return res.status(400).json({ error: err.message }); + } catch (err) { + return res.status(400).json({ error: (err as Error).message }); } }; } diff --git a/server/controllers/user.ts b/server/controllers/user.ts index fbc06d49..99bc0acc 100644 --- a/server/controllers/user.ts +++ b/server/controllers/user.ts @@ -15,15 +15,15 @@ class UserCtrl extends BaseCtrl { if (!user) { return res.sendStatus(403); } - return user.comparePassword(req.body.password, (error: any, isMatch: boolean) => { + return user.comparePassword(req.body.password, (error, isMatch: boolean) => { if (error || !isMatch) { return res.sendStatus(403); } const token = sign({ user }, secret, { expiresIn: '24h' }); return res.status(200).json({ token }); }); - } catch (err: any) { - return res.status(400).json({ error: err.message }); + } catch (err) { + return res.status(400).json({ error: (err as Error).message }); } }; diff --git a/server/models/cat.ts b/server/models/cat.ts index 4f0161a6..d02716b6 100644 --- a/server/models/cat.ts +++ b/server/models/cat.ts @@ -14,4 +14,5 @@ const catSchema = new Schema({ const Cat = model('Cat', catSchema); +export type { ICat }; export default Cat; diff --git a/server/models/user.ts b/server/models/user.ts index b4fbb4ed..f8cf91e3 100644 --- a/server/models/user.ts +++ b/server/models/user.ts @@ -7,6 +7,7 @@ interface IUser { password: string; role: string; isModified(password: string): boolean; + // eslint-disable-next-line @typescript-eslint/no-explicit-any comparePassword(password: string, callback: (err: any, isMatch: boolean) => void): boolean; } @@ -32,6 +33,7 @@ userSchema.pre('save', function(next): void { }); }); +// eslint-disable-next-line @typescript-eslint/no-explicit-any userSchema.methods.comparePassword = function(candidatePassword: string, callback: any): void { compare(candidatePassword, this.password, (err, isMatch) => { if (err) { return callback(err); } diff --git a/server/tsconfig.json b/server/tsconfig.json index afd2d2c3..4e48c520 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { "outDir": "../dist/server", "baseUrl": "", - "module": "commonjs", + "types": ["node", "jest"], "skipLibCheck": true // Added due to jest and jasmine errors } } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 96a14922..10cc21d4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,24 @@ -/* To learn more about this file see: https://angular.io/config/tsconfig. */ +/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */ +/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */ { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", - "forceConsistentCasingInFileNames": true, - "esModuleInterop": true, "strict": true, "noImplicitOverride": true, - "noPropertyAccessFromIndexSignature": false, // Default is true + "noPropertyAccessFromIndexSignature": false, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + "isolatedModules": true, + "esModuleInterop": true, "sourceMap": true, "declaration": false, "experimentalDecorators": true, - "moduleResolution": "node", + "moduleResolution": "bundler", "importHelpers": true, "target": "ES2022", "module": "ES2022", - "useDefineForClassFields": false, "lib": [ "ES2022", "dom" @@ -30,4 +30,4 @@ "strictInputAccessModifiers": true, "strictTemplates": true } -} +} \ No newline at end of file