mirror of
https://github.com/hexastack/hexabot
synced 2025-05-31 10:57:06 +00:00
fix: findOne and findById types
This commit is contained in:
parent
62e18ab591
commit
d3123268aa
@ -241,7 +241,7 @@ export abstract class BaseRepository<
|
||||
query: Query<T | null, T>,
|
||||
cls: new () => R,
|
||||
options?: ClassTransformOptions,
|
||||
): Promise<R> {
|
||||
): Promise<R | null> {
|
||||
const doc = await query.lean(this.leanOpts).exec();
|
||||
return plainToClass(cls, doc, options ?? this.transformOpts);
|
||||
}
|
||||
@ -256,8 +256,8 @@ export abstract class BaseRepository<
|
||||
}
|
||||
|
||||
return typeof criteria === 'string'
|
||||
? this.model.findById(criteria, projection)
|
||||
: this.model.findOne<T>(criteria, projection);
|
||||
? this.model.findById<HydratedDocument<T>>(criteria, projection)
|
||||
: this.model.findOne<HydratedDocument<T>>(criteria, projection);
|
||||
}
|
||||
|
||||
async findOne(
|
||||
@ -267,7 +267,7 @@ export abstract class BaseRepository<
|
||||
) {
|
||||
if (!criteria) {
|
||||
// @TODO : Issue a warning ?
|
||||
return Promise.resolve(undefined);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
const query = this.findOneQuery(criteria, projection);
|
||||
@ -277,7 +277,7 @@ export abstract class BaseRepository<
|
||||
async findOneAndPopulate(
|
||||
criteria: string | TFilterQuery<T>,
|
||||
projection?: ProjectionType<T>,
|
||||
): Promise<TFull> {
|
||||
): Promise<TFull | null> {
|
||||
this.ensureCanPopulate();
|
||||
const query = this.findOneQuery(criteria, projection).populate(
|
||||
this.populate,
|
||||
@ -474,7 +474,7 @@ export abstract class BaseRepository<
|
||||
async updateOne<D extends Partial<U>>(
|
||||
criteria: string | TFilterQuery<T>,
|
||||
dto: UpdateQuery<D>,
|
||||
): Promise<T> {
|
||||
): Promise<T | null> {
|
||||
const query = this.model.findOneAndUpdate<T>(
|
||||
{
|
||||
...(typeof criteria === 'string' ? { _id: criteria } : criteria),
|
||||
|
@ -33,7 +33,7 @@ export abstract class BaseService<
|
||||
criteria: string | TFilterQuery<T>,
|
||||
options?: ClassTransformOptions,
|
||||
projection?: ProjectionType<T>,
|
||||
): Promise<T> {
|
||||
): Promise<T | null> {
|
||||
return await this.repository.findOne(criteria, options, projection);
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ export abstract class BaseService<
|
||||
async updateOne<D extends Partial<Omit<T, keyof BaseSchema>>>(
|
||||
criteria: string | TFilterQuery<T>,
|
||||
dto: D,
|
||||
): Promise<T> {
|
||||
): Promise<T | null> {
|
||||
return await this.repository.updateOne(criteria, dto);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user