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
4f6cd08d
Commit
4f6cd08d
authored
Feb 05, 2021
by
chinguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add_delete_update_api
parent
840e93d9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
86 additions
and
56 deletions
+86
-56
students.ts
src/dao/students.ts
+22
-5
_index.ts
src/endpoints/students/_index.ts
+2
-1
students.delete.ts
src/endpoints/students/students.delete.ts
+3
-5
students.get.ts
src/endpoints/students/students.get.ts
+1
-1
students.post.ts
src/endpoints/students/students.post.ts
+3
-3
students.put.ts
src/endpoints/students/students.put.ts
+6
-0
students.ts
src/routes/students.ts
+3
-2
20210204092355-create-students.js
src/sqlz/migrations/20210204092355-create-students.js
+36
-33
students.ts
src/sqlz/models/students.ts
+10
-6
No files found.
src/dao/students.ts
View file @
4f6cd08d
import
*
as
uuid
from
'uuid'
import
*
as
uuid
from
'uuid'
import
{
Students
}
from
'./../sqlz/models/students'
;
import
{
Students
}
from
'./../sqlz/models/students'
export
function
create
(
students
:
any
):
Promise
<
any
>
{
export
function
create
(
students
:
any
):
Promise
<
any
>
{
return
Students
.
create
({
return
Students
.
create
({
id
:
uuid
.
v1
(),
id
:
uuid
.
v1
(),
code
:
students
.
code
,
firstname
:
students
.
firstname
,
firstname
:
students
.
firstname
,
lastname
:
students
.
lastname
,
lastname
:
students
.
lastname
,
email
:
students
.
email
,
email
:
students
.
email
,
sdt
:
students
.
sdt
sdt
:
students
.
sdt
})
})
}
}
export
function
findAll
():
Promise
<
any
>
{
export
function
findAll
():
Promise
<
any
>
{
return
Students
.
findAll
()
return
Students
.
findAll
()
}
}
export
function
deleteUser
(
id
:
any
):
Promise
<
any
>
{
export
function
deleteUser
(
code
:
any
):
Promise
<
any
>
{
return
Students
.
destroy
({
return
Students
.
destroy
({
where
:
{
id
:
id
}
where
:{
code
}
})
}
export
function
updateUser
(
code
:
any
,
students
:
any
):
Promise
<
any
>
{
return
Students
.
findOne
({
where
:
{
code
}
}).
then
(
function
(
student
)
{
if
(
student
)
{
student
.
update
({
firstname
:
students
.
firstname
,
lastname
:
students
.
lastname
,
email
:
students
.
email
,
sdt
:
students
.
sdt
})
}
})
})
}
}
src/endpoints/students/_index.ts
View file @
4f6cd08d
import
*
as
StudentsGet
from
'./students.get'
import
*
as
StudentsGet
from
'./students.get'
import
*
as
StudentsPost
from
'./students.post'
import
*
as
StudentsPost
from
'./students.post'
import
*
as
StudentsDelete
from
'./students.delete'
import
*
as
StudentsDelete
from
'./students.delete'
import
*
as
StudentsPut
from
'./students.put'
export
{
StudentsGet
,
StudentsPost
,
StudentsDelete
}
export
{
StudentsGet
,
StudentsPost
,
StudentsDelete
,
StudentsPut
}
\ No newline at end of file
\ No newline at end of file
src/endpoints/students/students.delete.ts
View file @
4f6cd08d
import
{
Request
,
Response
}
from
'express'
import
{
Request
,
Response
}
from
'express'
import
{
StudentDao
}
from
'../../dao/_index'
import
{
StudentDao
}
from
'../../dao/_index'
export
function
deleteUser
(
req
:
Request
,
res
:
Response
){
export
function
deleteUser
(
req
:
Request
,
res
:
Response
)
{
return
StudentDao
.
deleteUser
(
req
.
params
.
id
).
then
(
res
.
status
(
202
).
send
({
return
StudentDao
.
deleteUser
(
req
.
params
.
code
).
then
(
res
.
status
(
200
).
json
({
success
:
true
,
message
:
'delete success'
}))
message
:
'delete successfull'
}
})).
catch
(
error
=>
res
.
boom
.
badRequest
(
error
))
}
\ No newline at end of file
src/endpoints/students/students.get.ts
View file @
4f6cd08d
...
@@ -2,7 +2,7 @@ import { Request, Response } from 'express'
...
@@ -2,7 +2,7 @@ import { Request, Response } from 'express'
import
{
StudentDao
}
from
'../../dao/_index'
import
{
StudentDao
}
from
'../../dao/_index'
export
function
getAllUsers
(
req
:
Request
,
res
:
Response
){
export
function
getAllUsers
(
req
:
Request
,
res
:
Response
)
{
return
StudentDao
return
StudentDao
.
findAll
()
.
findAll
()
.
then
(
students
=>
res
.
status
(
200
).
send
(
students
))
.
then
(
students
=>
res
.
status
(
200
).
send
(
students
))
...
...
src/endpoints/students/students.post.ts
View file @
4f6cd08d
import
{
Request
,
Response
}
from
'express'
import
{
Request
,
Response
}
from
'express'
import
{
StudentDao
}
from
'../../dao/_index'
import
{
StudentDao
}
from
'../../dao/_index'
export
function
Add
(
req
:
Request
,
res
:
Response
){
export
function
Add
(
req
:
Request
,
res
:
Response
)
{
return
StudentDao
return
StudentDao
.
create
(
req
.
body
)
.
create
(
req
.
body
)
.
then
(
students
=>
res
.
status
(
20
1
).
send
(
students
))
.
then
(
students
=>
res
.
status
(
20
0
).
send
(
students
))
.
catch
(
error
=>
res
.
boom
.
badRequest
(
error
))
.
catch
(
error
=>
res
.
boom
.
badRequest
(
error
))
}
}
\ No newline at end of file
src/endpoints/students/students.put.ts
0 → 100644
View file @
4f6cd08d
import
{
Request
,
Response
}
from
'express'
import
{
StudentDao
}
from
'../../dao/_index'
export
function
updateUser
(
req
:
Request
,
res
:
Response
)
{
return
StudentDao
.
updateUser
(
req
.
params
.
code
,
req
.
body
).
then
(
res
.
status
(
200
).
json
({
success
:
true
,
message
:
'update successful'
}))
}
\ No newline at end of file
src/routes/students.ts
View file @
4f6cd08d
import
{
Express
}
from
'express'
import
{
Express
}
from
'express'
import
{
StudentsController
}
from
'../endpoints/_index'
import
{
StudentsController
}
from
'../endpoints/_index'
export
function
routes
(
app
:
Express
){
export
function
routes
(
app
:
Express
)
{
app
.
get
(
'/api/getStudents'
,
StudentsController
.
StudentsGet
.
getAllUsers
)
app
.
get
(
'/api/getStudents'
,
StudentsController
.
StudentsGet
.
getAllUsers
)
app
.
post
(
'/api/addStudent'
,
StudentsController
.
StudentsPost
.
Add
)
app
.
post
(
'/api/addStudent'
,
StudentsController
.
StudentsPost
.
Add
)
app
.
delete
(
'/api/deleteStudent'
,
StudentsController
.
StudentsDelete
.
deleteUser
)
app
.
delete
(
'/api/deleteStudent/:code'
,
StudentsController
.
StudentsDelete
.
deleteUser
)
app
.
put
(
'/api/updateStudent/:code'
,
StudentsController
.
StudentsPut
.
updateUser
)
}
}
\ No newline at end of file
src/sqlz/migrations/20210204092355-create-students.js
View file @
4f6cd08d
'use strict'
;
'use strict'
;
module
.
exports
=
{
module
.
exports
=
{
up
:
async
(
queryInterface
,
Sequelize
)
=>
{
up
:
async
(
queryInterface
,
Sequelize
)
=>
{
await
queryInterface
.
createTable
(
'Students'
,
{
await
queryInterface
.
createTable
(
'Students'
,
{
id
:
{
id
:
{
allowNull
:
false
,
allowNull
:
false
,
autoIncrement
:
true
,
primaryKey
:
true
,
primaryKey
:
true
,
type
:
Sequelize
.
UUID
,
type
:
Sequelize
.
INTEGER
defaultValue
:
Sequelize
.
UUIDV1
},
},
firstname
:
{
code
:
{
type
:
Sequelize
.
STRING
type
:
Sequelize
.
STRING
},
},
lastname
:
{
firstname
:
{
type
:
Sequelize
.
STRING
type
:
Sequelize
.
STRING
},
},
email
:
{
lastname
:
{
type
:
Sequelize
.
STRING
type
:
Sequelize
.
STRING
},
},
sdt
:
{
email
:
{
type
:
Sequelize
.
NUMBER
type
:
Sequelize
.
STRING
},
},
createdAt
:
{
sdt
:
{
allowNull
:
false
,
type
:
Sequelize
.
STRING
type
:
Sequelize
.
DATE
},
},
createdAt
:
{
updatedAt
:
{
allowNull
:
true
,
allowNull
:
false
,
type
:
Sequelize
.
DATE
type
:
Sequelize
.
DATE
},
}
updatedAt
:
{
});
allowNull
:
true
,
},
type
:
Sequelize
.
DATE
down
:
async
(
queryInterface
,
Sequelize
)
=>
{
}
await
queryInterface
.
dropTable
(
'Students'
);
});
}
},
down
:
async
(
queryInterface
,
Sequelize
)
=>
{
await
queryInterface
.
dropTable
(
'Students'
);
}
};
};
\ No newline at end of file
src/sqlz/models/students.ts
View file @
4f6cd08d
import
{
Model
,
STRING
,
UUID
,
Deferrable
,
NUMBER
}
from
'sequelize'
import
{
Model
,
STRING
,
UUID
,
Deferrable
,
NUMBER
,
DATE
,
INTEGER
,
BIGINT
}
from
'sequelize'
import
sequelize
from
'./_index'
import
sequelize
from
'./_index'
export
class
Students
extends
Model
{
export
class
Students
extends
Model
{
...
@@ -7,16 +7,20 @@ export class Students extends Model {
...
@@ -7,16 +7,20 @@ export class Students extends Model {
export
class
StudentsModel
{
export
class
StudentsModel
{
id
:
string
id
:
string
code
:
string
firstname
:
string
firstname
:
string
lastname
:
string
lastname
:
string
email
:
string
email
:
string
sdt
:
number
sdt
:
string
createdAt
:
Date
updatedAt
:
Date
}
}
Students
.
init
({
Students
.
init
({
firstname
:
STRING
(
50
),
code
:
STRING
,
lastname
:
STRING
(
50
),
firstname
:
STRING
,
email
:
STRING
(
50
),
lastname
:
STRING
,
sdt
:
NUMBER
email
:
STRING
,
sdt
:
STRING
},
{
},
{
sequelize
,
sequelize
,
modelName
:
'Students'
,
modelName
:
'Students'
,
...
...
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