UsersController
3import { User } from '@interfaces/users.interface';
4import userService from '@services/users.service';
5
6class UsersController { 7 public userService = new userService();
8
9 /**
createCookie
55 return { expiresIn, token: sign(dataStoredInToken, secretKey, { expiresIn }) };
56 }
57
58 public createCookie(tokenData: TokenData): string {59 return `Authorization=${tokenData.token}; HttpOnly; Max-Age=${tokenData.expiresIn};`;
60 }
61}
createToken
47 return findUser;
48 }
49
50 public createToken(user: User): TokenData {51 const dataStoredInToken: DataStoredInToken = { _id: user._id };
52 const secretKey: string = SECRET_KEY;
53 const expiresIn: number = 60 * 60;
logout
38 return { cookie, findUser };
39 }
40
41 public async logout(userData: User): Promise<User> {42 if (isEmpty(userData)) throw new HttpException(400, 'userData is empty');
43
44 const findUser: User = await this.users.findOne({ email: userData.email, password: userData.password });
login
23 return createUserData;
24 }
25
26 public async login(userData: UserDto): Promise<{ cookie: string; findUser: User }> {27 if (isEmpty(userData)) throw new HttpException(400, 'userData is empty');
28
29 const findUser: User = await this.users.findOne({ email: userData.email });
It is recommended to have documentation comments above, or right inside a function/class declaration. This helps developers, users and even the author understand the purpose of a code snippet or API function in the future.
NOTE: If you want to stop this issue from getting raised on certain constructs (arrow functions, class expressions, methods etc.), consider using the skipdoccoverage option under the analyzers.meta
property in your .deepsource.toml
file.
For example, the following configuration will silence this issue for class expressions and method definitions:
[analyzers.meta]
skip_doc_coverage = ["class-expression", "method-definition"]
function sum(a, b) {
return a + b;
}
/**
* Function to add two numbers
* @param a The first number to add
* @param b The second number to add
* @returns The sum of two numbers
*/
function sum(a, b) {
return a + b;
}