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
import * as express from 'express' | |
class App { | |
public express | |
constructor() { | |
this.express = express() | |
this.loadRoutes() | |
} | |
private loadRoutes() : void { | |
const router = express.Router() |
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
import app from './App' | |
app.listen(3000, (err) => { | |
if (err) return console.log(err) | |
return console.log('Server is running in port: ', 3000); | |
}) |
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
{ | |
"name": "ts-server", | |
"version": "1.0.0", | |
"description": "", | |
"main": "server.js", | |
"scripts": { | |
"build": "./node_modules/.bin/tsc", | |
"start": "npm run build && node dist/server.js", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, |
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
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "es6", | |
"module": "commonjs", | |
"outDir": "dist", | |
"sourceMap": true | |
}, | |
"include": [ | |
"src/**/*.ts" |
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
class User { | |
public name: String | |
public email: String | |
public role: String | |
private pwd: String | |
private ID: Number | |
constructor() | |
constructor(email: String) | |
constructor(name: String, email: 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
import User from './User' | |
import Student from './Student' | |
class Teacher extends User { | |
constructor() | |
constructor(email: String) | |
constructor(name: String, email: String) | |
constructor(name: String, email: String, pwd: String) | |
constructor(name?: String, email?: String, pwd?: String) { | |
super(name, email, pwd, 'teacher') |
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
import User from './User' | |
class Student extends User { | |
constructor() | |
constructor(email: String) | |
constructor(name: String, email: String) | |
constructor(name: String, email: String, pwd: String) | |
constructor(name?: String, email?: String, pwd?: String) { | |
super(name, email, pwd, 'student') | |
} |
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
import * as express from 'express' | |
import Teacher from './../models/Teacher' | |
import Student from './../models/Student' | |
import User from '../models/User'; | |
import JSONResponse from '../libs/JSONResponse' | |
const router = express.Router() | |
router.post('/register', (req, res) => { | |
try { | |
let user: 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
import * as express from 'express' | |
import router from './routes/index' | |
import * as bodyParser from 'body-parser'; | |
class App { | |
public express | |
constructor() { | |
this.express = express() | |
this.express.use(bodyParser.json({ limit: '50mb' })) | |
this.loadRoutes() | |
} |
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
class JSONResponse { | |
constructor() {} | |
static success(req, res, message, data) { | |
res.status(200).json({ | |
code: 200, | |
message: message || 'success', | |
data: data, | |
}); | |
} |
OlderNewer