Skip to content

Instantly share code, notes, and snippets.

@eduardopc
Created December 14, 2020 02:31
Show Gist options
  • Save eduardopc/a2b44b752ba62de79db69aa73945ccb7 to your computer and use it in GitHub Desktop.
Save eduardopc/a2b44b752ba62de79db69aa73945ccb7 to your computer and use it in GitHub Desktop.
import { BaseService } from "../../base";
import { Animal, AnimalModel } from "../entities/animals";
export class AnimalService extends BaseService<Animal> {
constructor() {
super();
this.model = AnimalModel;
}
async findAllAnimalsAndPickOne() {
const animals = await this.model.find({});
const idx = Math.floor(Math.random() * animals.length);
return animals[idx];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment