Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
meanspec-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MeanSpec (SCE338 2024-2 Group 1)
meanspec-backend
Commits
bf7d3007
Verified
Commit
bf7d3007
authored
5 months ago
by
Eunhak Lee
Browse files
Options
Downloads
Patches
Plain Diff
feat: 내 PC의 공유 uuid 만들기
parent
b7f7c909
Branches
Branches containing commit
No related tags found
1 merge request
!20
내 PC를 인증된 조합으로 공유하기 기능
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/repositories/shareRepository.js
+30
-0
30 additions, 0 deletions
src/repositories/shareRepository.js
src/routes/my.js
+12
-0
12 additions, 0 deletions
src/routes/my.js
src/services/myService.js
+15
-0
15 additions, 0 deletions
src/services/myService.js
with
57 additions
and
0 deletions
src/repositories/shareRepository.js
0 → 100644
+
30
−
0
View file @
bf7d3007
import
pool
from
'
../db.js
'
;
const
ShareRepository
=
{
async
createCombinationUuid
(
combinationId
)
{
const
resp
=
await
pool
.
query
(
`INSERT INTO shares (combination_id)
VALUES ($1)
RETURNING uuid;`
,
[
combinationId
]
);
const
[
uuid
]
=
resp
.
rows
;
return
uuid
;
},
async
getCombinationByUuid
(
uniqueId
)
{
const
resp
=
await
pool
.
query
(
`SELECT
shares.combination_id,
array(SELECT relations.part_id FROM relations WHERE relations.combination_id = shares.combination_id) as parts,
shares.created_at,
(SELECT created_at FROM combinations WHERE combinations.id = shares.combination_id) as updated_at
FROM shares
WHERE uuid=$1;`
,
[
uniqueId
]
);
const
[
row
]
=
resp
.
rows
;
return
row
;
},
};
export
default
ShareRepository
;
This diff is collapsed.
Click to expand it.
src/routes/my.js
+
12
−
0
View file @
bf7d3007
...
@@ -43,6 +43,18 @@ myRouter.patch(
...
@@ -43,6 +43,18 @@ myRouter.patch(
})
})
);
);
myRouter
.
post
(
'
/combination/:combinationId/uuid
'
,
authMiddleware
,
wrapAsync
(
async
(
req
,
res
)
=>
{
const
{
combinationId
}
=
req
.
params
;
const
userId
=
req
.
user
?.
userId
;
const
uuid
=
await
myService
.
createCombinationUuid
(
userId
,
combinationId
);
res
.
sendResponse
(
''
,
200
,
{
uuid
});
})
);
myRouter
.
get
(
myRouter
.
get
(
'
/registration-code
'
,
'
/registration-code
'
,
authMiddleware
,
authMiddleware
,
...
...
This diff is collapsed.
Click to expand it.
src/services/myService.js
+
15
−
0
View file @
bf7d3007
import
{
Redis
}
from
'
../redis.js
'
;
import
{
Redis
}
from
'
../redis.js
'
;
import
{
ReportableError
}
from
'
../errors.js
'
;
import
{
ReportableError
}
from
'
../errors.js
'
;
import
myRepository
from
'
../repositories/myRepository.js
'
;
import
myRepository
from
'
../repositories/myRepository.js
'
;
import
ShareRepository
from
'
../repositories/shareRepository.js
'
;
import
crypto
from
'
crypto
'
;
import
crypto
from
'
crypto
'
;
const
myService
=
{
const
myService
=
{
...
@@ -163,6 +164,20 @@ const myService = {
...
@@ -163,6 +164,20 @@ const myService = {
message
:
'
조합 이름이 성공적으로 변경되었습니다.
'
,
message
:
'
조합 이름이 성공적으로 변경되었습니다.
'
,
};
};
},
},
async
createCombinationUuid
(
userId
,
combinationId
)
{
if
(
!
userId
||
!
combinationId
)
throw
new
ReportableError
(
400
,
'
올바르지 않은 요청입니다.
'
);
const
combination
=
await
myRepository
.
getCombinationById
(
combinationId
);
if
(
!
combination
)
throw
new
ReportableError
(
404
,
'
조합을 찾을 수 없습니다.
'
);
if
(
combination
.
userId
!==
userId
)
throw
new
ReportableError
(
403
,
'
해당 조합에 대한 권한이 없습니다.
'
);
return
await
ShareRepository
.
createCombinationUuid
(
combinationId
);
},
};
};
export
default
myService
;
export
default
myService
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment