mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
Connect to mongodb, define schemas
This commit is contained in:
1 parent
d51a75e5bc
commit
50443b96e0
13 files changed
+216
-12
No files matched your search
@@ -11,6 +11,7 @@
|
||||
"dependencies": {
|
||||
"dockerode": "^3.3.5",
|
||||
"express": "^4.18.2",
|
||||
"mongoose": "^7.4.0",
|
||||
"socket.io": "^4.7.1",
|
||||
"socket.io-client": "^4.7.1",
|
||||
"swagger-ui-express": "^5.0.0",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
title: Hello World
|
||||
order: 1
|
||||
---
|
||||
|
||||
# Hello World
|
||||
@@ -0,0 +1,10 @@
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
export default async function connectDB() {
|
||||
try {
|
||||
await mongoose.connect('mongodb://localhost:27017/odyssey-test')
|
||||
console.log('Connected to MongoDB')
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,13 @@ import YAML from 'yaml'
|
||||
import swaggerUI from 'swagger-ui-express'
|
||||
|
||||
import socketServer from './api/socket.js'
|
||||
import connectDB from './db.js'
|
||||
|
||||
const port = 3000
|
||||
const app = express()
|
||||
const server = http.createServer(app)
|
||||
socketServer(server)
|
||||
connectDB()
|
||||
|
||||
const file = fs.readFileSync('./swagger.yaml', 'utf8')
|
||||
const swaggerDocument = YAML.parse(file)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export { default as User } from './user.js'
|
||||
export { default as Session } from './session.js'
|
||||
export { default as Quest } from './quest.js'
|
||||
@@ -0,0 +1,10 @@
|
||||
import { model } from 'mongoose'
|
||||
|
||||
export default model(
|
||||
'Quest',
|
||||
{
|
||||
name: String,
|
||||
description: String,
|
||||
},
|
||||
{ timestamp: true }
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
import { model, Schema } from 'mongoose'
|
||||
|
||||
export default model(
|
||||
'Session',
|
||||
{
|
||||
name: String,
|
||||
containerId: String,
|
||||
user: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'User',
|
||||
},
|
||||
quest: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'Quest',
|
||||
},
|
||||
finishedAt: Date,
|
||||
terminals: [String],
|
||||
},
|
||||
{ timestamps: true }
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
export default mongoose.model('User', {
|
||||
username: String,
|
||||
password: String,
|
||||
email: String,
|
||||
})
|
||||
+4
-4
@@ -38,9 +38,9 @@ paths:
|
||||
- signed-in
|
||||
summary: create a new session for current user
|
||||
parameters:
|
||||
- name: exercise_id
|
||||
- name: quest_id
|
||||
in: query
|
||||
description: pass the exercise id
|
||||
description: pass the quest id
|
||||
required: true
|
||||
style: form
|
||||
explode: true
|
||||
@@ -274,7 +274,7 @@ components:
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
Exercise:
|
||||
Quest:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
@@ -290,7 +290,7 @@ components:
|
||||
user_id:
|
||||
type: string
|
||||
format: uuid
|
||||
exercise_id:
|
||||
quest_id:
|
||||
type: string
|
||||
format: uuid
|
||||
created_at:
|
||||
|
||||
Reference in new issue
Block a user