Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"mongoose": "^5.13.7",
"mongoose": "^6.0.4",
"morgan": "^1.10.0",
"swagger-ui-express": "^4.1.6",
"tsoa": "^3.9.0"
Expand Down
14 changes: 10 additions & 4 deletions src/models/token.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Schema, model } from 'mongoose'
import { Token } from '../types'
import { Token, UserClaim } from '../types'
import { validateTokenCode } from '../services/token'

const UserClaimSchema = new Schema<UserClaim>({
tag: String,
id: String,
claimedAt: String
})

const TokenSchema = new Schema<Token>({
code: {
type: String,
Expand Down Expand Up @@ -36,19 +42,19 @@ const TokenSchema = new Schema<Token>({
required: true
},
claimedBy: {
type: Array,
type: [UserClaimSchema],
required: true
},
createdBy: {
type: String,
required: true
},
createdAt: {
type: Date,
type: String,
required: true
},
expireAt: {
type: Date
type: String
}
})

Expand Down
13 changes: 8 additions & 5 deletions src/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Schema, model } from 'mongoose'
import { User } from '../types'
import { User, UserClaimedToken } from '../types'

const UserClaimedTokenSchema = new Schema<UserClaimedToken>({
code: String,
value: Number,
claimedAt: String
})

const UserSchema = new Schema<User>({
userId: {
Expand All @@ -10,15 +16,12 @@ const UserSchema = new Schema<User>({
type: String,
required: true
},
username: {
type: String
},
score: {
type: Number,
required: true
},
tokens: {
type: Array,
type: [UserClaimedTokenSchema],
required: true
}
})
Expand Down
6 changes: 1 addition & 5 deletions src/services/mongoose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ export async function connectMongoose (): Promise<typeof mongoose> {
try {
if (mongoose.connection.readyState === 0) {
const mongoAddress = `mongodb+srv://${process.env.MONGODB_USER}:${process.env.MONGODB_PASSWORD}@${process.env.MONGODB_URL}/${process.env.MONGODB_DATABASE}?retryWrites=true&w=majority`
return mongoose.connect(mongoAddress, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
})
return mongoose.connect(mongoAddress)
}
} catch (error) {
console.log(error)
Expand Down
Loading