This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { GraphQLInputObjectType, GraphQLString } from "graphql"; | |
| // User input is getting input from user | |
| const UserInput = new GraphQLInputObjectType({ | |
| name: "UserInputLogin", | |
| fields: { | |
| username: { type: GraphQLString }, | |
| password: { type: GraphQLString }, | |
| }, | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { GraphQLBoolean, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLNonNull, GraphQLObjectType, GraphQLString } from "graphql"; | |
| // User type | |
| const userType = new GraphQLObjectType({ | |
| name: "User", | |
| fields: { | |
| id: { type: GraphQLID }, | |
| username: { type: GraphQLString }, | |
| name: { type: GraphQLString }, | |
| password: { type: GraphQLString }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import bcrypt = require("bcrypt-nodejs"); | |
| import { Schema } from "mongoose"; | |
| import mongoose = require("mongoose"); | |
| mongoose.Promise = global.Promise; | |
| /** | |
| * This is Schema for User | |
| * @constant {UserSchema} | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class Response { | |
| public code: number; | |
| public message: string; | |
| public data: any; | |
| constructor(code: number, message: string, data: any) { | |
| this.code = code; | |
| this.message = message; | |
| this.data = data; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Response } from "../models"; | |
| export function completeRequest(promise: Promise<Response>): any { | |
| const res = promise.then((response) => { | |
| const finallResponse = { | |
| code: response.code, | |
| message: response.message, | |
| data: response.data, | |
| }; | |
| return finallResponse; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {Document} from "mongoose"; | |
| /** | |
| * This is interface for user | |
| * @interface | |
| * @extends {Document} | |
| */ | |
| export interface IUser extends Document { | |
| // tslint:disable-next-line:semicolon | |
| username: string, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import jwt = require("jsonwebtoken"); | |
| import { model } from "mongoose"; | |
| import { completeRequest } from "../functions/complete"; | |
| import { IUser } from "../interfaces"; | |
| import { Response } from "../models"; | |
| import { UserSchema } from "../schemas"; | |
| import { Config } from "../shared"; | |
| const User = model("User", UserSchema); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const query = `mutation registerUser($input: UserInputRegister) { | |
| registerUser(input: $input) { | |
| code | |
| message | |
| data { | |
| token | |
| success | |
| user { | |
| id | |
| createdAt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const query = `query loginUser($input: UserInputLogin) { | |
| loginUser(input: $input) { | |
| code, | |
| message, | |
| data { | |
| success | |
| user { | |
| id | |
| name | |
| username |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import chai = require("chai"); | |
| import chaiAsPromised = require("chai-as-promised"); | |
| import chaiHttp = require("chai-http"); | |
| import { suite, test } from "mocha-typescript"; | |
| import { model } from "mongoose"; | |
| import sinon = require("sinon"); | |
| import { Response } from "../models"; | |
| import { UserSchema } from "../schemas"; | |
| import { TodoApp } from "../server"; | |
| import { Config } from "../shared"; |