refactor: Use input params for all mutations

This commit is contained in:
Faruk AYDIN
2022-03-08 01:13:16 +03:00
committed by Ömer Faruk Aydın
parent 212523aec6
commit bb36748764
14 changed files with 149 additions and 60 deletions

View File

@@ -3,18 +3,20 @@ import jwt from 'jsonwebtoken';
import appConfig from '../../config/app';
type Params = {
email: string;
password: string;
input: {
email: string;
password: string;
};
};
const TOKEN_EXPIRES_IN = '14d';
const login = async (_parent: unknown, params: Params) => {
const user = await User.query().findOne({
email: params.email,
email: params.input.email,
});
if (user && (await user.login(params.password))) {
if (user && (await user.login(params.input.password))) {
const token = jwt.sign({ userId: user.id }, appConfig.appSecretKey, {
expiresIn: TOKEN_EXPIRES_IN,
});