Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
chinguyen_nodejs_managestudents
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chinguyen
chinguyen_nodejs_managestudents
Commits
840e93d9
Commit
840e93d9
authored
Feb 04, 2021
by
chinguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
edd4a923
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
128 additions
and
1 deletion
+128
-1
_index.ts
src/dao/_index.ts
+2
-0
students.ts
src/dao/students.ts
+23
-0
_index.ts
src/endpoints/_index.ts
+2
-1
_index.ts
src/endpoints/students/_index.ts
+5
-0
students.delete.ts
src/endpoints/students/students.delete.ts
+8
-0
students.get.ts
src/endpoints/students/students.get.ts
+10
-0
students.post.ts
src/endpoints/students/students.post.ts
+9
-0
_index.ts
src/routes/_index.ts
+2
-0
students.ts
src/routes/students.ts
+8
-0
20210204092355-create-students.js
src/sqlz/migrations/20210204092355-create-students.js
+36
-0
students.ts
src/sqlz/models/students.ts
+23
-0
No files found.
src/dao/_index.ts
View file @
840e93d9
import
*
as
LanguagesDao
from
'./languages'
import
*
as
LanguagesDao
from
'./languages'
import
*
as
AppUserDao
from
'./appusers'
import
*
as
AppUserDao
from
'./appusers'
import
*
as
StudentDao
from
'./students'
export
{
LanguagesDao
}
export
{
LanguagesDao
}
export
{
AppUserDao
}
export
{
AppUserDao
}
export
{
StudentDao
}
src/dao/students.ts
0 → 100644
View file @
840e93d9
import
*
as
uuid
from
'uuid'
import
{
Students
}
from
'./../sqlz/models/students'
;
export
function
create
(
students
:
any
):
Promise
<
any
>
{
return
Students
.
create
({
id
:
uuid
.
v1
(),
firstname
:
students
.
firstname
,
lastname
:
students
.
lastname
,
email
:
students
.
email
,
sdt
:
students
.
sdt
})
}
export
function
findAll
():
Promise
<
any
>
{
return
Students
.
findAll
()
}
export
function
deleteUser
(
id
:
any
):
Promise
<
any
>
{
return
Students
.
destroy
({
where
:
{
id
:
id
}
})
}
src/endpoints/_index.ts
View file @
840e93d9
import
*
as
LanguageController
from
'./languages/_index'
import
*
as
LanguageController
from
'./languages/_index'
import
*
as
AppUserController
from
'./appusers/_index'
import
*
as
AppUserController
from
'./appusers/_index'
import
*
as
StudentsController
from
'./students/_index'
export
{
LanguageController
,
AppUserController
}
export
{
LanguageController
,
AppUserController
,
StudentsController
}
src/endpoints/students/_index.ts
0 → 100644
View file @
840e93d9
import
*
as
StudentsGet
from
'./students.get'
import
*
as
StudentsPost
from
'./students.post'
import
*
as
StudentsDelete
from
'./students.delete'
export
{
StudentsGet
,
StudentsPost
,
StudentsDelete
}
\ No newline at end of file
src/endpoints/students/students.delete.ts
0 → 100644
View file @
840e93d9
import
{
Request
,
Response
}
from
'express'
import
{
StudentDao
}
from
'../../dao/_index'
export
function
deleteUser
(
req
:
Request
,
res
:
Response
){
return
StudentDao
.
deleteUser
(
req
.
params
.
id
).
then
(
res
.
status
(
202
).
send
({
message
:
'delete successfull'
})).
catch
(
error
=>
res
.
boom
.
badRequest
(
error
))
}
\ No newline at end of file
src/endpoints/students/students.get.ts
0 → 100644
View file @
840e93d9
import
{
Request
,
Response
}
from
'express'
import
{
StudentDao
}
from
'../../dao/_index'
export
function
getAllUsers
(
req
:
Request
,
res
:
Response
){
return
StudentDao
.
findAll
()
.
then
(
students
=>
res
.
status
(
200
).
send
(
students
))
.
catch
(
error
=>
res
.
boom
.
badRequest
(
error
))
}
\ No newline at end of file
src/endpoints/students/students.post.ts
0 → 100644
View file @
840e93d9
import
{
Request
,
Response
}
from
'express'
import
{
StudentDao
}
from
'../../dao/_index'
export
function
Add
(
req
:
Request
,
res
:
Response
){
return
StudentDao
.
create
(
req
.
body
)
.
then
(
students
=>
res
.
status
(
201
).
send
(
students
))
.
catch
(
error
=>
res
.
boom
.
badRequest
(
error
))
}
\ No newline at end of file
src/routes/_index.ts
View file @
840e93d9
...
@@ -2,6 +2,7 @@ import * as winston from 'winston'
...
@@ -2,6 +2,7 @@ import * as winston from 'winston'
import
{
Express
,
Request
,
Response
}
from
'express'
import
{
Express
,
Request
,
Response
}
from
'express'
import
*
as
LanguagesRoutes
from
'./languages'
import
*
as
LanguagesRoutes
from
'./languages'
import
*
as
AppUserRoutes
from
'./appusers'
import
*
as
AppUserRoutes
from
'./appusers'
import
*
as
StudentsRoutes
from
'./students'
export
function
initRoutes
(
app
:
Express
)
{
export
function
initRoutes
(
app
:
Express
)
{
winston
.
log
(
'info'
,
'--> Initialisations des routes'
)
winston
.
log
(
'info'
,
'--> Initialisations des routes'
)
...
@@ -12,6 +13,7 @@ export function initRoutes(app: Express) {
...
@@ -12,6 +13,7 @@ export function initRoutes(app: Express) {
LanguagesRoutes
.
routes
(
app
)
LanguagesRoutes
.
routes
(
app
)
AppUserRoutes
.
routes
(
app
)
AppUserRoutes
.
routes
(
app
)
StudentsRoutes
.
routes
(
app
)
app
.
all
(
'*'
,
(
req
:
Request
,
res
:
Response
)
=>
res
.
boom
.
notFound
())
app
.
all
(
'*'
,
(
req
:
Request
,
res
:
Response
)
=>
res
.
boom
.
notFound
())
}
}
src/routes/students.ts
0 → 100644
View file @
840e93d9
import
{
Express
}
from
'express'
import
{
StudentsController
}
from
'../endpoints/_index'
export
function
routes
(
app
:
Express
){
app
.
get
(
'/api/getStudents'
,
StudentsController
.
StudentsGet
.
getAllUsers
)
app
.
post
(
'/api/addStudent'
,
StudentsController
.
StudentsPost
.
Add
)
app
.
delete
(
'/api/deleteStudent'
,
StudentsController
.
StudentsDelete
.
deleteUser
)
}
\ No newline at end of file
src/sqlz/migrations/20210204092355-create-students.js
0 → 100644
View file @
840e93d9
'use strict'
;
module
.
exports
=
{
up
:
async
(
queryInterface
,
Sequelize
)
=>
{
await
queryInterface
.
createTable
(
'Students'
,
{
id
:
{
allowNull
:
false
,
autoIncrement
:
true
,
primaryKey
:
true
,
type
:
Sequelize
.
INTEGER
},
firstname
:
{
type
:
Sequelize
.
STRING
},
lastname
:
{
type
:
Sequelize
.
STRING
},
email
:
{
type
:
Sequelize
.
STRING
},
sdt
:
{
type
:
Sequelize
.
NUMBER
},
createdAt
:
{
allowNull
:
false
,
type
:
Sequelize
.
DATE
},
updatedAt
:
{
allowNull
:
false
,
type
:
Sequelize
.
DATE
}
});
},
down
:
async
(
queryInterface
,
Sequelize
)
=>
{
await
queryInterface
.
dropTable
(
'Students'
);
}
};
\ No newline at end of file
src/sqlz/models/students.ts
0 → 100644
View file @
840e93d9
import
{
Model
,
STRING
,
UUID
,
Deferrable
,
NUMBER
}
from
'sequelize'
import
sequelize
from
'./_index'
export
class
Students
extends
Model
{
}
export
class
StudentsModel
{
id
:
string
firstname
:
string
lastname
:
string
email
:
string
sdt
:
number
}
Students
.
init
({
firstname
:
STRING
(
50
),
lastname
:
STRING
(
50
),
email
:
STRING
(
50
),
sdt
:
NUMBER
},
{
sequelize
,
modelName
:
'Students'
,
})
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment