Skip to content

Commit

Permalink
feat: add databse (#1777)
Browse files Browse the repository at this point in the history
  • Loading branch information
suzy-g38 authored Jul 20, 2023
1 parent 139e42b commit 2019690
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 8 deletions.
155 changes: 155 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
/dist
yarn.lock
package-lock.json
package-lock.json
.env
6 changes: 4 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
"author": "",
"license": "ISC",
"dependencies": {
"@types/cors": "^2.8.13",

"concurrently": "^8.2.0",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"mongoose": "^7.4.0",
"typescript": "^5.1.6"
},
"devDependencies": {
"@types/express": "^4.17.17"
"@types/express": "^4.17.17",
"@types/cors": "^2.8.13"
}
}
20 changes: 15 additions & 5 deletions server/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import express,{Express, Response, Request} from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import {projectRouter} from './src'
import { mongoConnect } from './src/schema/mongo.connect';
import { projectRouter } from './src/projects/projects.router';
import { userRouter } from './src/user/user.router';
const app:Express = express();
const port = 8000
const port = process.env.PORT

dotenv.config()
app.use(cors())
Expand All @@ -14,7 +16,15 @@ app.get('/', (req: Request, res: Response) => {
})
app.use('/api/project',projectRouter)
app.use('api/user', userRouter)
app.listen(port,()=>{
console.log("app is listening on port: ",port)
})

async function startServer() {
try {
await mongoConnect()
app.listen(port, () => console.log(`Server is running on port ${port}`))
} catch (error) {
console.error('Error starting the server:', error)
process.exit(1)
}
}

startServer()
2 changes: 2 additions & 0 deletions server/src/projects/project.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ export interface AllProjectsType {
github_username: string
Social_media: SocialMediaType[]
projects: ProjectsType[]
github_repo_link: string
deployment_url: string
}
26 changes: 26 additions & 0 deletions server/src/schema/Projects/project.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { model, Schema } from 'mongoose'

const ProjectsSchema = new Schema({
name: {
type: String,
require: true,
},
description: {
type: String,
require: true,
},
tech: [{ type: String, require: true }],
github_username: {
type: String,
require: true,
},
github_repo_link:{
type: String,
require: true,
},
deployment_url:{
type: String,
require: true,
}
})
export const ProjectModel = model('Projects', ProjectsSchema)
18 changes: 18 additions & 0 deletions server/src/schema/User/user.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import mongoose, {model, Schema} from 'mongoose';

const UserSchema = new Schema({
name: {
type: String,
required: true,
},
bio: {
type: String,
required: true,
},
socials: [{ name: String, link: String }],
image: { type: String, required: true },
projects: [{ type: mongoose.Types.ObjectId, ref: 'Projects' }],
})


export const UserModel = model('User', UserSchema)
13 changes: 13 additions & 0 deletions server/src/schema/mongo.connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import mongoose, { connect } from 'mongoose'

mongoose.set('strictQuery', false)

export const mongoConnect = async () => {
const connectionString = process.env.MONGODB_DATABASE_URL as string
try {
console.log('connection')
await connect(connectionString)
} catch (error) {
throw new Error(error as string)
}
}

0 comments on commit 2019690

Please sign in to comment.