In my Nest JS service, the code structure is as follows:
import { Injectable } from '@nestjs/common';
import { Model } from 'mongoose';
import { InjectModel } from '@nestjs/mongoose';
import { Collection } from './interfaces/collection.interface';
import { CollectionDto } from './dto/collection.dto';
import { COLLECTION } from '../constants';
@Injectable()
export class CollectionsService {
constructor(
@InjectModel(COLLECTION) private readonly collectionModel: Model<Collection>
) {}
async getAllCollections(): Promise<Collection[]> {
const collections = await this.collectionModel.find().exec();
return collections;
}
async addCollection(collectionDto: CollectionDto): Promise<Collection> {
const newCollection = await this.collectionModel(collectionDto);
return newCollection.save();
}
}
Although the code works fine, I encountered a tslint warning ts(2348).
Can anyone suggest an alternative approach to resolve this issue without using the // @ts-ignore
rule?