(
entityName: EntityName<T>,
where: FilterQuery<T>,
options: FindOneOptions<T, P, F, E> = { populate: [], orderBy: {} },
)
| 227 | } |
| 228 | |
| 229 | async findOne<T extends object, P extends string = never, F extends string = never, E extends string = never>( |
| 230 | entityName: EntityName<T>, |
| 231 | where: FilterQuery<T>, |
| 232 | options: FindOneOptions<T, P, F, E> = { populate: [], orderBy: {} }, |
| 233 | ): Promise<EntityData<T> | null> { |
| 234 | if (this.metadata.find(entityName)?.virtual) { |
| 235 | const [item] = await this.findVirtual(entityName, where, options as FindOptions<T, any, any, any>); |
| 236 | /* v8 ignore next */ |
| 237 | return item ?? null; |
| 238 | } |
| 239 | |
| 240 | if (Utils.isPrimaryKey(where)) { |
| 241 | where = this.buildFilterById(entityName, where as string); |
| 242 | } |
| 243 | |
| 244 | const fields = this.buildFields( |
| 245 | entityName, |
| 246 | (options.populate as unknown as PopulateOptions<T>[]) || [], |
| 247 | options.fields, |
| 248 | options.exclude as any[], |
| 249 | ); |
| 250 | where = this.renameFields(entityName, where as T, true); |
| 251 | const orderBy = Utils.asArray(options.orderBy).map(orderBy => this.renameFields(entityName, orderBy as T, true)); |
| 252 | const res = await this.rethrow( |
| 253 | this.getConnection('read').find(entityName, where, { |
| 254 | orderBy, |
| 255 | limit: 1, |
| 256 | fields, |
| 257 | ctx: options.ctx, |
| 258 | loggerContext: options.logging, |
| 259 | ...this.buildQueryOptions(options), |
| 260 | }), |
| 261 | ); |
| 262 | |
| 263 | return this.mapResult<T>(res[0], this.metadata.find(entityName)); |
| 264 | } |
| 265 | |
| 266 | override async findVirtual<T extends object>( |
| 267 | entityName: EntityName<T>, |
nothing calls this directly
no test coverage detected