Skip to content

Commit

Permalink
Remove type any in BaseCtrl in favor of generic class (#284)
Browse files Browse the repository at this point in the history
* Update base.ts

Remove type any in favor of generic class

* Update cat.ts

Add generic type to BaseCtrl

* Update user.ts

Add generic type to BaseCtrl

* chore: remove double space

---------

Co-authored-by: Davide Violante <[email protected]>
  • Loading branch information
adwulfran and DavideViolante authored Oct 10, 2024
1 parent f0bc600 commit fc2e1eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions server/controllers/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Request, Response } from 'express';
import { Model } from 'mongoose';

abstract class BaseCtrl {
abstract class BaseCtrl<T> {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
abstract model: any;
abstract model:Model<T>

// Get all
getAll = async (req: Request, res: Response) => {
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/cat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Cat from '../models/cat';
import Cat, { ICat } from '../models/cat';
import BaseCtrl from './base';

class CatCtrl extends BaseCtrl {
class CatCtrl extends BaseCtrl<ICat> {
model = Cat;
}

Expand Down
4 changes: 2 additions & 2 deletions server/controllers/user.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { sign, Secret } from 'jsonwebtoken';
import { Request, Response } from 'express';

import User from '../models/user';
import User, { IUser } from '../models/user';
import BaseCtrl from './base';

const secret: Secret = process.env.SECRET_TOKEN as string;

class UserCtrl extends BaseCtrl {
class UserCtrl extends BaseCtrl<IUser> {
model = User;

login = async (req: Request, res: Response) => {
Expand Down

0 comments on commit fc2e1eb

Please sign in to comment.