Toggle navigation
Toggle navigation
This project
Loading...
Sign in
송용우
/
oss-Jaksimsamil
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
송용우
2020-08-21 16:53:53 +0900
1
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2cd393eb0247df2509978acb6df6b1759a519732
2cd393eb
1 parent
70f9fca2
Update profile API to use User model
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
11 deletions
jaksimsamil-server/src/api/auth/auth.ctrl.js
jaksimsamil-server/src/api/profile/profile.ctrl.js
jaksimsamil-server/src/api/auth/auth.ctrl.js
View file @
2cd393e
const
Joi
=
require
(
"joi"
);
const
User
=
require
(
"../../models/user"
);
const
Profile
=
require
(
"../../models/profile"
);
/*
POST /api/auth/register
{
...
...
@@ -28,14 +27,10 @@ exports.register = async (ctx) => {
ctx
.
status
=
409
;
return
;
}
const
profile
=
new
Profile
({
username
,
});
const
user
=
new
User
({
username
,
});
await
user
.
setPassword
(
password
);
await
profile
.
save
();
await
user
.
save
();
ctx
.
body
=
user
.
serialize
();
...
...
jaksimsamil-server/src/api/profile/profile.ctrl.js
View file @
2cd393e
const
Profile
=
require
(
"../../models/profile
"
);
const
User
=
require
(
"../../models/user
"
);
const
mongoose
=
require
(
"mongoose"
);
const
getBJ
=
require
(
"../../util/getBJ"
);
const
Joi
=
require
(
"joi"
);
...
...
@@ -16,6 +16,7 @@ exports.checkObjectId = (ctx, next) => {
}
return
next
();
};
/*POST /api/profile/getprofile
{
username: "username"
...
...
@@ -24,7 +25,7 @@ exports.checkObjectId = (ctx, next) => {
exports
.
getProfile
=
async
(
ctx
)
=>
{
try
{
const
{
username
}
=
ctx
.
request
.
body
;
const
profile
=
await
Profile
.
findByUsername
(
username
);
const
profile
=
await
User
.
findByUsername
(
username
);
if
(
!
profile
)
{
ctx
.
status
=
401
;
return
;
...
...
@@ -58,7 +59,7 @@ exports.setProfile = async (ctx) => {
}
try
{
const
profile
=
await
Profile
.
findOneAndUpdate
(
const
profile
=
await
User
.
findOneAndUpdate
(
{
username
:
ctx
.
request
.
body
.
username
},
ctx
.
request
.
body
,
{
...
...
@@ -90,7 +91,7 @@ exports.syncBJ = async function (ctx) {
}
try
{
const
profile
=
await
Profile
.
findByUsername
(
username
);
const
profile
=
await
User
.
findByUsername
(
username
);
if
(
!
profile
)
{
ctx
.
status
=
401
;
return
;
...
...
@@ -98,7 +99,7 @@ exports.syncBJ = async function (ctx) {
const
BJID
=
await
profile
.
getBJID
();
let
BJdata
=
await
getBJ
.
getBJ
(
BJID
);
let
BJdata_date
=
await
analyzeBJ
.
analyzeBJ
(
BJdata
);
const
updateprofile
=
await
Profile
.
findOneAndUpdate
(
const
updateprofile
=
await
User
.
findOneAndUpdate
(
{
username
:
username
},
{
solvedBJ
:
BJdata
,
solvedBJ_date
:
BJdata_date
},
{
new
:
true
}
...
...
@@ -123,7 +124,7 @@ exports.recommend = async (ctx) => {
return
;
}
try
{
const
profile
=
await
Profile
.
findByUsername
(
username
);
const
profile
=
await
User
.
findByUsername
(
username
);
if
(
!
profile
)
{
ctx
.
status
=
401
;
return
;
...
...
송용우
@2019102188
2020-09-26 12:41:26 UTC
Mentioned in commit
be144e59
Please
register
or
login
to post a comment