Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
exam_12_Tsoy_Danil
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Цой Данил
exam_12_Tsoy_Danil
Commits
8ac0a8fb
Commit
8ac0a8fb
authored
Apr 15, 2023
by
Цой Данил
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrote services + added db connection to mongoose db. Check back for working + added fixtures file
parent
1f83bb7e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1738 additions
and
78 deletions
+1738
-78
package-lock.json
backend/package-lock.json
+1657
-70
package.json
backend/package.json
+17
-7
index.ts
backend/src/index.ts
+10
-1
photosService.ts
backend/src/services/photosService.ts
+30
-0
usersService.ts
backend/src/services/usersService.ts
+24
-0
No files found.
backend/package-lock.json
View file @
8ac0a8fb
This diff is collapsed.
Click to expand it.
backend/package.json
View file @
8ac0a8fb
{
{
"name"
:
"
backend
"
,
"name"
:
"
homework
"
,
"version"
:
"1.0.0"
,
"version"
:
"1.0.0"
,
"description"
:
""
,
"description"
:
""
,
"main"
:
"index.js"
,
"main"
:
"index.js"
,
"scripts"
:
{
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
,
"dev"
:
"ts-node-dev --respawn --trace-warnings --transpile-only src/index.ts"
,
"dev"
:
"ts-node-dev --respawn --trace-warnings --transpile-only src/index.ts"
,
"seed"
:
"ts-node-dev --trace-warnings --transpile-only src/fixtures.ts"
"seed"
:
"ts-node-dev --trace-warnings --transpile-only src/fixtures.ts"
,
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
},
"author"
:
""
,
"author"
:
""
,
"license"
:
"ISC"
,
"license"
:
"ISC"
,
"dependencies"
:
{
"dependencies"
:
{
"@types/cors"
:
"^2.8.13"
,
"@types/cors"
:
"^2.8.13"
,
"@types/
mongoose"
:
"^5.11.97
"
,
"@types/
jsonwebtoken"
:
"^9.0.1
"
,
"@types/shortid"
:
"^0.0.29"
,
"@types/shortid"
:
"^0.0.29"
,
"bcrypt"
:
"^5.1.0"
,
"bcrypt"
:
"^5.1.0"
,
"cors"
:
"^2.8.5"
,
"cors"
:
"^2.8.5"
,
"dotenv"
:
"^16.0.3"
,
"dotenv"
:
"^16.0.3"
,
"express"
:
"^4.18.2"
,
"express"
:
"^4.18.2"
,
"jsonwebtoken"
:
"^9.0.0"
,
"jsonwebtoken"
:
"^9.0.0"
,
"mongodb"
:
"^5.1.0"
,
"mongoose"
:
"^7.0.3"
,
"mongoose"
:
"^7.0.3"
,
"multer"
:
"^1.4.5-lts.1"
,
"multer"
:
"^1.4.5-lts.1"
,
"shortid"
:
"^2.2.16"
"pg"
:
"^8.10.0"
,
"pg-hstore"
:
"^2.3.4"
,
"sequelize"
:
"^6.29.3"
,
"sequelize-typescript"
:
"^2.1.5"
,
"shortid"
:
"^2.2.16"
,
"uuid"
:
"^9.0.0"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@types/bcrypt"
:
"^5.0.0"
,
"@types/bcrypt"
:
"^5.0.0"
,
"@types/dotenv"
:
"^8.2.0"
,
"@types/dotenv"
:
"^8.2.0"
,
"@types/express"
:
"^4.17.17"
,
"@types/express"
:
"^4.17.17"
,
"@types/jsonwebtoken"
:
"^9.0.1"
,
"@types/mongodb"
:
"^4.0.7"
,
"@types/multer"
:
"^1.4.7"
"@types/mongoose"
:
"^5.11.97"
,
"@types/multer"
:
"^1.4.7"
,
"@types/uuid"
:
"^9.0.1"
,
"@types/validator"
:
"^13.7.14"
,
"ts-node-dev"
:
"^2.0.0"
}
}
}
}
backend/src/index.ts
View file @
8ac0a8fb
...
@@ -2,6 +2,7 @@ import express, { Express } from "express";
...
@@ -2,6 +2,7 @@ import express, { Express } from "express";
import
dotenv
from
'dotenv'
;
import
dotenv
from
'dotenv'
;
import
cors
from
'cors'
;
import
cors
from
'cors'
;
import
{
healthCheckController
}
from
"./controllers/healthCheckController"
;
import
{
healthCheckController
}
from
"./controllers/healthCheckController"
;
import
{
mongooseDB
}
from
"./repository/mongooseDB"
;
dotenv
.
config
()
dotenv
.
config
()
...
@@ -20,8 +21,16 @@ class App {
...
@@ -20,8 +21,16 @@ class App {
this
.
app
.
listen
(
process
.
env
.
APP_PORT
,
()
=>
{
this
.
app
.
listen
(
process
.
env
.
APP_PORT
,
()
=>
{
console
.
log
(
`Server is running on http://localhost:
${
process
.
env
.
APP_PORT
}
`
);
console
.
log
(
`Server is running on http://localhost:
${
process
.
env
.
APP_PORT
}
`
);
})
})
await
mongooseDB
.
init
()
process
.
on
(
'exit'
,
()
=>
{
mongooseDB
.
close
()
})
}
catch
(
err
:
unknown
){
}
catch
(
err
:
unknown
){
console
.
log
(
err
);
console
.
log
(
err
);
}
}
}
}
}
}
\ No newline at end of file
const
app
=
new
App
()
app
.
init
()
\ No newline at end of file
backend/src/services/photosService.ts
0 → 100644
View file @
8ac0a8fb
import
IPhoto
from
"../interfaces/IPhoto"
;
import
IPhotoDto
from
"../interfaces/IPhotoDto"
;
import
IResponse
from
"../interfaces/IResponse"
;
import
{
MongooseDB
,
mongooseDB
}
from
"../repository/mongooseDB"
;
export
class
PhotosService
{
private
repository
:
MongooseDB
constructor
(){
this
.
repository
=
mongooseDB
}
public
getAllPhotos
=
async
():
Promise
<
IResponse
<
IPhoto
[]
|
null
>>
=>
{
return
await
this
.
repository
.
getAllPhotos
()
}
public
deletePhotoById
=
async
(
id
:
string
,
user
:
string
):
Promise
<
IResponse
<
IPhoto
|
null
>>
=>
{
return
await
this
.
repository
.
deletePhotoById
(
id
,
user
)
}
public
getPhotosByUserId
=
async
(
id
:
string
):
Promise
<
IResponse
<
IPhoto
[]
|
null
>>
=>
{
return
await
this
.
repository
.
getPhotosByUserId
(
id
)
}
public
addPhoto
=
async
(
photoDto
:
IPhotoDto
):
Promise
<
IResponse
<
IPhoto
|
null
>>
=>
{
return
await
this
.
repository
.
addPhoto
(
photoDto
)
}
}
export
const
photosService
=
new
PhotosService
()
\ No newline at end of file
backend/src/services/usersService.ts
0 → 100644
View file @
8ac0a8fb
import
{
EStatuses
}
from
"../enum/EStatuses"
;
import
IPhoto
from
"../interfaces/IPhoto"
;
import
IPhotoDto
from
"../interfaces/IPhotoDto"
;
import
IResponse
from
"../interfaces/IResponse"
;
import
IUserCreateDto
from
"../interfaces/IUserCreateDto"
;
import
IUserGetDto
from
"../interfaces/IUserGetDto"
;
import
{
mongooseDB
,
MongooseDB
}
from
"../repository/mongooseDB"
;
export
class
UsersService
{
private
repository
:
MongooseDB
constructor
(){
this
.
repository
=
mongooseDB
}
public
createUser
=
async
(
userDto
:
IUserCreateDto
):
Promise
<
IResponse
<
IUserGetDto
|
null
>>
=>
{
return
await
this
.
repository
.
createUser
(
userDto
)
}
public
loginUser
=
async
(
userDto
:
IUserCreateDto
):
Promise
<
IResponse
<
IUserGetDto
|
null
>>
=>
{
return
await
this
.
repository
.
loginUser
(
userDto
)
}
}
export
const
usersService
=
new
UsersService
()
\ 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