Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
hw87AlenBolatov
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
Болатов Ален
hw87AlenBolatov
Commits
96aa4852
Commit
96aa4852
authored
Mar 14, 2023
by
Болатов Ален
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1
connected mangoose and added artist model
parent
80fe2db2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
516 additions
and
4 deletions
+516
-4
.env
backend/.env
+2
-0
package-lock.json
backend/package-lock.json
+440
-1
package.json
backend/package.json
+6
-2
index.ts
backend/src/index.ts
+11
-1
artist.ts
backend/src/routes/artist.ts
+47
-0
environment.d.ts
backend/src/types/environment.d.ts
+10
-0
No files found.
backend/.env
0 → 100644
View file @
96aa4852
MONGO_URL='mongodb://localhost:27017'
PORT='3000'
\ No newline at end of file
backend/package-lock.json
View file @
96aa4852
This diff is collapsed.
Click to expand it.
backend/package.json
View file @
96aa4852
...
...
@@ -10,10 +10,14 @@
"author"
:
""
,
"license"
:
"ISC"
,
"dependencies"
:
{
"@types/node"
:
"^18.15.3"
,
"dotenv"
:
"^16.0.3"
,
"express"
:
"^4.18.2"
,
"mongoose"
:
"^7.0.1"
,
"ts-node-dev"
:
"^2.0.0"
},
"devDependencies"
:
{
"@types/express"
:
"^4.17.17"
"@types/express"
:
"^4.17.17"
,
"@types/mongoose"
:
"^5.11.97"
}
}
backend/src/index.ts
View file @
96aa4852
import
express
,
{
Express
}
from
'express'
;
import
express
,
{
Express
,
json
}
from
'express'
;
import
mongoose
from
'mongoose'
;
import
'dotenv/config'
;
import
{
artistRouter
}
from
'./routes/artist'
;
const
app
:
Express
=
express
();
app
.
use
(
json
());
app
.
use
(
'/artists'
,
artistRouter
);
app
.
listen
(
process
.
env
.
PORT
,
()
=>
{
console
.
log
(
'Server started on port '
+
process
.
env
.
PORT
);
});
backend/src/routes/artist.ts
0 → 100644
View file @
96aa4852
import
express
,
{
Request
,
Response
}
from
'express'
;
import
{
model
,
Schema
,
connect
,
Document
,
HydratedDocument
}
from
'mongoose'
;
const
router
=
express
.
Router
();
interface
IArtist
{
name
:
string
;
image
?:
File
;
description
:
string
;
}
const
artistSchema
=
new
Schema
<
IArtist
>
({
name
:
{
type
:
String
,
required
:
true
,
},
image
:
{
type
:
Buffer
,
},
description
:
{
type
:
String
,
required
:
true
,
},
});
const
Artist
=
model
<
IArtist
>
(
'Artist'
,
artistSchema
);
const
run
=
async
()
=>
{
await
connect
(
`
${
process
.
env
.
MONGO_URL
}
/artist`
);
};
run
().
catch
((
err
)
=>
console
.
log
(
err
));
router
.
get
(
'/'
,
(
req
:
Request
,
res
:
Response
)
=>
{
return
res
.
send
(
'Hello'
);
});
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
artist
:
HydratedDocument
<
IArtist
>
=
new
Artist
({
name
:
req
.
body
.
name
,
description
:
req
.
body
.
description
,
});
await
artist
.
save
();
res
.
send
(
artist
);
});
export
{
router
as
artistRouter
};
backend/src/types/environment.d.ts
0 → 100644
View file @
96aa4852
declare
global
{
namespace
NodeJS
{
interface
ProcessEnv
{
PORT
:
string
;
MONGO_URL
:
string
;
}
}
}
export
{};
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