How to use the @typegoose/typegoose.index function in @typegoose/typegoose

To help you get started, we’ve selected a few @typegoose/typegoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github L-Leite / cso2-users-service / src / entities / usersession.ts View on Github external
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

@typegoose/typegoose

Define Mongoose models using TypeScript classes

MIT
Latest version published 10 days ago

Package Health Score

89 / 100
Full package analysis