-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented crud over user table on mysql db
- Loading branch information
Showing
14 changed files
with
164 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
dist |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Attach by Process ID", | ||
"processId": "${command:PickProcess}", | ||
"request": "attach", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"type": "node" | ||
} | ||
|
||
] | ||
} |
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { NextFunction, Request, Response } from 'express'; | ||
import { UserData } from '../interfaces/user.interface'; | ||
import userService from '../services/user.service'; | ||
|
||
class UsersController { | ||
public userService = new userService(); | ||
|
||
public getUserByEmail = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const email: string = req.params.email; | ||
const findOneUserData: UserData = await this.userService.findUserDataByEmail(email); | ||
|
||
res.status(200).json({ data: findOneUserData, message: 'findOne' }); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
} | ||
|
||
export default UsersController; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { IsString, IsNotEmpty } from 'class-validator'; | ||
|
||
export class CreateUserDto { | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
public email: string; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
public password: string; | ||
} | ||
|
||
|
||
|
||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface UserData { | ||
_id: number; | ||
email: string; | ||
password: string; | ||
created_dttm: string; | ||
updated_dttm: string; | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Sequelize, DataTypes } from 'sequelize'; | ||
import User from './user.model'; | ||
import { DB_HOST, DB_PASSWORD, DB_USERNAME } from '../config/index'; | ||
|
||
const sequelize = new Sequelize(`mysql://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/slash`); | ||
|
||
const databaseObj = { | ||
Sequelize, | ||
sequelize, | ||
User : User(sequelize, Sequelize, DataTypes), | ||
}; | ||
|
||
export default databaseObj; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const User = (sequelize, Sequelize, DataTypes) => { | ||
const User = sequelize.define( | ||
"users", | ||
{ | ||
email: { | ||
type: DataTypes.STRING, | ||
unique: true, | ||
primaryKey: true | ||
}, | ||
password: { | ||
type: DataTypes.STRING | ||
} | ||
}, | ||
{ | ||
createdAt: "created_dttm", | ||
updatedAt: "updated_dttm" | ||
} | ||
); | ||
return User; | ||
}; | ||
|
||
export default User; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
import { Router } from 'express'; | ||
import { Routes } from '../interfaces/routes.interface'; | ||
|
||
class HealthRoute implements Routes { | ||
public route = '/health'; | ||
public router = Router(); | ||
public healthController = new HealthController(); | ||
|
||
constructor() { | ||
this.initializeRoutes(); | ||
} | ||
|
||
private initializeRoutes() { | ||
this.router.get(`${this.route}`, this.healthController.healthCheck); | ||
} | ||
} | ||
|
||
export default HealthRoute; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Router } from 'express'; | ||
import UsersController from '../controllers/user.controller'; | ||
import { Routes } from '../interfaces/routes.interface'; | ||
|
||
class UsersRoute implements Routes { | ||
public route = '/user'; | ||
public router = Router(); | ||
public usersController = new UsersController(); | ||
|
||
constructor() { | ||
this.initializeRoutes(); | ||
} | ||
|
||
private initializeRoutes() { | ||
this.router.get(`${this.route}/:email`, this.usersController.getUserByEmail); | ||
} | ||
} | ||
|
||
export default UsersRoute; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { UserData } from '../interfaces/user.interface'; | ||
import { HttpException } from '../utils/exception'; | ||
import Db from '../models'; | ||
import * as R from 'ramda'; | ||
import { nullCheck } from '../utils/ramda'; | ||
|
||
class UserService { | ||
|
||
public async findUserDataByEmail(email: string): Promise<UserData> { | ||
if (nullCheck(email)) throw new HttpException(400, "email is undefined"); | ||
|
||
const userResult: UserData = await Db.User.findByPk(email); | ||
if (!userResult) throw new HttpException(204, ''); | ||
|
||
return userResult; | ||
} | ||
|
||
} | ||
|
||
export default UserService; |