Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// return true if deleted only one document (val.n) with success (val.ok)
return res.ok === 1 && res.n === 1
}
/**
* delete every session saved in the database
* @returns true if deleted successfully, false if not
*/
public static async deleteAll(): Promise {
const res: { ok?: number; } = await UserSessionModel.deleteMany({})
.exec()
return res.ok === 1
}
@typegoose.prop({ required: true })
public sessionId: string
@typegoose.prop({ min: 1, required: true })
public userId: number
@typegoose.prop({ default: new SessionNetworkInfo(), required: true })
public externalNet: SessionNetworkInfo
@typegoose.prop({ default: new SessionNetworkInfo(), required: true })
public internalNet: SessionNetworkInfo
@typegoose.prop({ default: 0, required: true })
public currentChannelServerIndex: number
@typegoose.prop({ default: 0, required: true })
public currentChannelIndex: number
@typegoose.prop({ default: 0, required: true })
public currentRoomId: number
import * as typegoose from '@typegoose/typegoose'
import uuid from 'uuid/v4'
import { SessionNetworkInfo } from 'entities/sessionnetworkinfo'
/**
* Handles an user's session information
*/
@typegoose.index({ sessionId: 1, userId: 1 }, { unique: true })
export class UserSession {
/**
* retrieve every session in the db
* @param colOffset the index where the collection should begin
* @param colLength the collection's length
* @returns a promise with the sessions
*/
public static async getAll(colOffset: number, colLength: number): Promise {
return UserSessionModel.find({}).skip(colOffset).limit(colLength)
.exec()
}
/**
* retrieve an user's session by its owning user's ID
* @param userId the owning user's ID
* @returns the requested UserSession, if found. otherwise it will return a null object
import * as typegoose from '@typegoose/typegoose'
/**
* an user's session network information
*/
export class SessionNetworkInfo {
@typegoose.prop({ default: '0.0.0.0', required: true })
public ipAddress: string
@typegoose.prop({ default: 0, min: 0, max: 65535, required: true })
public clientPort: number
@typegoose.prop({ default: 0, min: 0, max: 65535, required: true })
public serverPort: number
@typegoose.prop({ default: 0, min: 0, max: 65535, required: true })
public tvPort: number
}
* @returns the uservars document
*/
private static async getInstance(): Promise {
return UserVarsModel.findOne({})
.exec()
}
/**
* create a new document
*/
private static async createDoc(): Promise {
const newInfo = new UserVarsModel({ nextUserId: DEFAULT_NEXTUSERID_VALUE })
await newInfo.save()
}
@typegoose.prop()
public nextUserId?: number
}
const UserVarsModel = typegoose.getModelForClass(UserVars)
return 0
}
const targetHash: HashContainer = await HashContainer.from(user.password)
const inputHash: HashContainer = await targetHash.cloneSettings(password)
if (targetHash.compare(inputHash) === false) {
return 0
}
return user.userId
}
@typegoose.prop({ index: true, required: true, unique: true })
public userId: number
@typegoose.prop({ lowercase: true, required: true, unique: true })
public userName: string
@typegoose.prop({ index: true, required: true, unique: true })
public playerName: string
@typegoose.prop({ required: true })
public password: string
@typegoose.prop({ default: 1, max: USER_MAX_LEVEL, required: true })
public level: number
@typegoose.prop({ default: 1005, required: true })
public avatar: number
@typegoose.prop({ default: 0, required: true })
public curExp: number
@typegoose.prop({ default: 1000, required: true })
public maxExp: number
@typegoose.prop({ default: 0, required: true })
public rank: number
@typegoose.prop({ default: 1, required: true })
.exec()
}
/**
* create a new document
*/
private static async createDoc(): Promise {
const newInfo = new UserVarsModel({ nextUserId: DEFAULT_NEXTUSERID_VALUE })
await newInfo.save()
}
@typegoose.prop()
public nextUserId?: number
}
const UserVarsModel = typegoose.getModelForClass(UserVars)
public rank: number
@typegoose.prop({ default: 1, required: true })
public vipLevel: number
@typegoose.prop({ default: 1, min: 0, max: 7, required: true })
public wins: number
@typegoose.prop({ default: 0, required: true })
public losses: number
@typegoose.prop({ default: 0, required: true })
public kills: number
@typegoose.prop({ default: 0, required: true })
public deaths: number
@typegoose.prop({ default: 0, required: true })
public assists: number
}
const UserModel = typegoose.getModelForClass(User)
@typegoose.prop({ default: new SessionNetworkInfo(), required: true })
public externalNet: SessionNetworkInfo
@typegoose.prop({ default: new SessionNetworkInfo(), required: true })
public internalNet: SessionNetworkInfo
@typegoose.prop({ default: 0, required: true })
public currentChannelServerIndex: number
@typegoose.prop({ default: 0, required: true })
public currentChannelIndex: number
@typegoose.prop({ default: 0, required: true })
public currentRoomId: number
}
const UserSessionModel = typegoose.getModelForClass(UserSession)
import { prop, modelOptions } from '@typegoose/typegoose'
import { ApiProperty } from '@nestjs/swagger'
@modelOptions({
schemaOptions: {
timestamps: true
}
})
export class User {
@ApiProperty({ description: '用户名', example: 'user1' })
@prop()
username: string
@ApiProperty({ description: '密码', example: 'pass1' })
@prop()
password: string
}
import { prop, modelOptions, arrayProp, Ref } from '@typegoose/typegoose';
import { ApiProperty } from '@nestjs/swagger';
import { Episode } from './episode.model';
@modelOptions({
schemaOptions: {
timestamps: true,
toJSON: { virtuals: true },
},
})
export class Course {
@ApiProperty({ description: '课程名称' })
@prop()
name: string;
@ApiProperty({ description: '封面图' })
@prop()
cover: string;
@arrayProp({
ref: 'Episode',