mongoose#model TypeScript Examples
The following examples show how to use
mongoose#model.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.module.ts From adminjs-nestjs with MIT License | 6 votes |
@Module({
imports: [
MongooseModule.forRoot('mongodb://localhost:27017/nest'),
AdminModule.createAdminAsync({
imports: [
MongooseSchemasModule,
],
inject: [
getModelToken('Admin'),
],
useFactory: (adminModel: Model<Admin>) => ({
adminJsOptions: {
rootPath: '/admin',
resources: [
{ resource: adminModel },
],
},
auth: {
authenticate: async (email, password) => Promise.resolve({ email: 'test' }),
cookieName: 'test',
cookiePassword: 'testPass',
},
}),
customLoader: ExpressCustomLoader,
}),
MongooseSchemasModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
Example #2
Source File: typegoose-middleware.ts From convoychat with GNU General Public License v3.0 | 6 votes |
TypegooseMiddleware: MiddlewareFn = async (_, next) => {
const result = await next();
if (Array.isArray(result)) {
return result.map(item =>
item instanceof Model ? convertDocument(item) : item
);
}
if (result instanceof Model) {
return convertDocument(result);
}
return result;
}
Example #3
Source File: course.service.ts From edu-server with MIT License | 6 votes |
constructor(
@InjectModel('Course') private readonly CourseModel: Model<Course>,
@InjectModel('Schedule') private readonly ScheduleModel: Model<Schedule>,
@InjectModel('Review') private readonly ReviewModel: Model<Review>,
@InjectModel('Doubt') private readonly DoubtModel: Model<Doubt>,
@InjectModel('DoubtAnswer')
private readonly DoubtAnswerModel: Model<DoubtAnswer>,
@InjectModel('Assignment')
private readonly AssignmentModel: Model<Assignment>,
@InjectModel('Lecture') private readonly LectureModel: Model<Lecture>,
@InjectModel('Mentor') private readonly mentorModel: Model<Mentor>,
) {}
Example #4
Source File: pins.service.ts From Phantom with MIT License | 6 votes |
constructor(
@InjectModel('Pin') private readonly pinModel: Model<pin>,
@InjectModel('Board') private readonly boardModel: Model<board>,
@InjectModel('User') private readonly userModel: Model<user>,
@InjectModel('Topic') private readonly topicModel: Model<topic>,
private ValidationService: ValidationService,
private BoardService: BoardService,
private NotificationService: NotificationService,
private EmailService: Email,
) {
this.HelpersUtils = new HelpersUtils();
}
Example #5
Source File: base.ts From pebula-node with MIT License | 6 votes |
export class GtModelContainer extends Model {
static readonly [GT_DOCUMENT] = true;
private static [GT_LOCAL_INFO]: GtLocalInfo;
private static [GT_DISCRIMINATOR_ROOT]?: typeof GtModelContainer;
private readonly [CTOR_INVOKED] = true;
static ctor<T extends GtModelContainer>(this: Ctor<T>, doc: Partial<T>): T {
if (this[GT_DISCRIMINATOR_ROOT] === this) {
const localInfo = findSchemaContainerOfChildDiscriminator(doc, this[GT_LOCAL_INFO]);
return new localInfo.cls(doc) as any;
} else {
return new this(doc);
}
}
static [Symbol.hasInstance](instance: any): boolean {
if (hasInstance.call(this, instance)) {
return true;
} else if (instance.schema) {
if (instance.schema === this.schema || hasExtendingSchema(instance.schema, this[GT_LOCAL_INFO].container.hierarchy.extending)) {
return true;
}
}
return false;
}
constructor(doc?: any) {
super();
if (this.constructor[GT_DISCRIMINATOR_ROOT] === this.constructor) {
throw new Error(`Directly instantiating the base discriminator type is not allowed`);
}
if (doc) {
const localInfo = findSchemaContainerOfChildDiscriminator(doc, this.constructor[GT_LOCAL_INFO]);
syncModelInstance(doc, this, localInfo, true);
}
}
}
Example #6
Source File: model-methods.ts From server with GNU General Public License v3.0 | 6 votes |
/**
* Add Data into Database of the Particular Model after Verification
*
* @async
* @param {Model} model - Model in the Database
* @param {Object} data - Data to be Added to Database
* @param {IUserDoc} admin - Admin user Document from Database
* @param {Readonly<IPolicy>[]} policies - Array of Policies Applicable for the Function
* @returns {Promise<Document>} - Saved Document
*/
export async function addDatatoDatabase<
T,
U extends Document,
V extends Model<U>,
>(
model: V,
data: T,
admin: IUserDoc,
policies: Readonly<IPolicy>[],
): Promise<U> {
await checkPolicy(policies, admin);
const newData = new model(data);
const savedData = await newData.save();
return savedData;
}
Example #7
Source File: generateModel.ts From davinci with MIT License | 6 votes |
/**
* Create an instance of a Mongoose model
* @param classSchema
* @param modelName
* @param collectionName
* @param options
*/
export function generateModel<T>(
classSchema: ClassType,
modelName = classSchema.name,
collectionName?,
options?: SchemaOptions
) {
const schema = generateSchema(classSchema, options);
return model(modelName, schema, collectionName) as T & ModelType<T>;
}
Example #8
Source File: analytics.ts From one-platform with MIT License | 5 votes |
Analytics: Model<AnalyticsModel> = model<AnalyticsModel, AnalyticsModelStatic>(
'Analytics',
AnalyticsSchema,
)
Example #9
Source File: ChannelModel.ts From vt-api with GNU Affero General Public License v3.0 | 5 votes |
Channels: Model<ChannelProps> = model('Channels', ChannelSchema)
Example #10
Source File: BaseMongoRepository.ts From node-experience with MIT License | 5 votes |
protected repository: Model<D>;
Example #11
Source File: User.ts From dropify with MIT License | 5 votes |
User: Model<IUser> = model("User", UserSchema)
Example #12
Source File: users.repository.ts From nest-js-boilerplate with MIT License | 5 votes |
constructor(@InjectModel(User.name) private usersModel: Model<UserDocument>) {}
Example #13
Source File: sequence.service.ts From whispr with MIT License | 5 votes |
constructor(@InjectModel('Sequence') private sequenceModel: Model<ISequence>) {}
Example #14
Source File: application.service.ts From uniauth-backend with MIT License | 5 votes |
constructor(
@InjectModel(Application.name) private applicationModel: Model<ApplicationDocument>,
@InjectModel('User') private userModel: Model<UserDocument>,
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger = new Logger('application'),
) {}
Example #15
Source File: DashboardUser.ts From aero-bot with MIT License | 5 votes |
dashboardUsers: Model<IDashboardUser> =
models["dashboard-users"] || model("dashboard-users", dashboardUserSchema)
Example #16
Source File: MusicChannel.ts From Lavalink-Music-Bot with GNU Affero General Public License v3.0 | 5 votes |
IMusic: Model<IMusicInterface> = model("IMusic", IMusicSchema)
Example #17
Source File: preAuth.middleware.ts From edu-server with MIT License | 5 votes |
constructor(@InjectModel('User') private readonly userModel: Model<User>) {}
Example #18
Source File: app.service.ts From nestjs-file-streaming with MIT License | 5 votes |
constructor(
@InjectModel('fs.files') private readonly fileModel: Model<File>,
@InjectConnection() private readonly connection: Connection,
) {
this.bucket = new mongo.GridFSBucket(this.connection.db)
}
Example #19
Source File: users.seeder.ts From nestjs-seeder with MIT License | 5 votes |
constructor(@InjectModel(User.name) private readonly user: Model<User>) {}
Example #20
Source File: product.repository.mongo.ts From nest-js-products-api with MIT License | 5 votes |
constructor(
@InjectModel('Product') private readonly productModel: Model<ProductEntity>,
) {}
Example #21
Source File: database-models.providers.spec.ts From nestjs-rest-sample with GNU General Public License v3.0 | 5 votes |
describe('DatabaseModelsProviders', () => {
let conn: any;
let userModel: any;
let postModel: any;
let commentModel: any;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
...databaseModelsProviders,
{
provide: DATABASE_CONNECTION,
useValue: {
model: jest
.fn()
.mockReturnValue({} as Model<User | Post | Comment>),
},
},
],
}).compile();
conn = module.get<Connection>(DATABASE_CONNECTION);
userModel = module.get<UserModel>(USER_MODEL);
postModel = module.get<PostModel>(POST_MODEL);
commentModel = module.get<CommentModel>(COMMENT_MODEL);
});
it('DATABASE_CONNECTION should be defined', () => {
expect(conn).toBeDefined();
});
it('USER_MODEL should be defined', () => {
expect(userModel).toBeDefined();
});
it('POST_MODEL should be defined', () => {
expect(postModel).toBeDefined();
});
it('COMMENT_MODEL should be defined', () => {
expect(commentModel).toBeDefined();
});
});
Example #22
Source File: board.service.ts From Phantom with MIT License | 5 votes |
constructor(
@InjectModel('Board') private readonly boardModel: Model<board>,
@InjectModel('Pin') private readonly pinModel: Model<pin>,
@InjectModel('Topic') private readonly topicModel: Model<topic>,
@InjectModel('User') private readonly userModel: Model<user>,
private ValidationService: ValidationService,
) {}
Example #23
Source File: cats.service.ts From nestjs-tenancy with MIT License | 5 votes |
constructor(
@InjectModel(Cat.name) private readonly catModel: Model<Cat>
) { }
Example #24
Source File: mongo.ts From pancake-nft-api with GNU General Public License v3.0 | 5 votes |
getModel = async (name: string): Promise<Model<any>> => {
connection = await getConnection();
return connection.model(name);
}
Example #25
Source File: document-array-path.ts From pebula-node with MIT License | 5 votes |
discriminator<U extends Document>(name: string, schema: Schema, value?: string): Model<U> {
const created = extendEmbeddedDocument(super.discriminator(name, schema, value));
this.casterConstructor.discriminators[name] = created;
return created as any;
}
Example #26
Source File: user-profile.db.model.ts From nestjs-angular-starter with MIT License | 5 votes |
UserProfileDbModel: Model<IUserProfileDbModel> = model<
IUserProfileDbModel
>('user', UserProfileSchema)
Example #27
Source File: auth.service.ts From NextJS-NestJS-GraphQL-Starter with MIT License | 5 votes |
constructor(
@InjectModel('User') private readonly userModel: Model<User>,
@InjectModel('Session') private readonly sessionModel: Model<Session>,
) {}
Example #28
Source File: analytics.ts From one-platform with MIT License | 5 votes |
Analytics: Model<AnalyticsModel> = model<AnalyticsModel, AnalyticsModelStatic>(
'Analytics',
AnalyticsSchema,
)