Skip to content

Commit

Permalink
adapt tsconfig to angular v18
Browse files Browse the repository at this point in the history
eanble no-explicit-any rule again and fix errors
  • Loading branch information
DavideViolante committed Aug 31, 2024
1 parent 32a7774 commit f97a75d
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 31 deletions.
8 changes: 4 additions & 4 deletions client/app/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class UserService {
return this.http.post<User>('/api/user', user);
}

login(credentials: { email: string; password: string }): Observable<any> {
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<User[]> {
Expand All @@ -33,11 +33,11 @@ export class UserService {
return this.http.get<User>(`/api/user/${user._id}`);
}

editUser(user: User): Observable<any> {
editUser(user: User): Observable<string> {
return this.http.put(`/api/user/${user._id}`, user, { responseType: 'text' });
}

deleteUser(user: User): Observable<any> {
deleteUser(user: User): Observable<string> {
return this.http.delete(`/api/user/${user._id}`, { responseType: 'text' });
}

Expand Down
2 changes: 0 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
29 changes: 15 additions & 14 deletions server/controllers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { Request, Response } from 'express';

abstract class BaseCtrl {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
abstract model: any;

// Get all
getAll = async (req: Request, res: Response) => {
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 });
}
};

Expand All @@ -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 });
}
};

Expand All @@ -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 });
}
};

Expand All @@ -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 });
}
};

Expand All @@ -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 });
}
};

Expand All @@ -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 });
}
};

Expand All @@ -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 });
}
};
}
Expand Down
6 changes: 3 additions & 3 deletions server/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
};

Expand Down
1 change: 1 addition & 0 deletions server/models/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ const catSchema = new Schema<ICat>({

const Cat = model<ICat>('Cat', catSchema);

export type { ICat };
export default Cat;
2 changes: 2 additions & 0 deletions server/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -32,6 +33,7 @@ userSchema.pre<IUser>('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); }
Expand Down
2 changes: 1 addition & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"outDir": "../dist/server",
"baseUrl": "",
"module": "commonjs",
"types": ["node", "jest"],
"skipLibCheck": true // Added due to jest and jasmine errors
}
}
14 changes: 7 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -30,4 +30,4 @@
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
}

0 comments on commit f97a75d

Please sign in to comment.