fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-11 11:56:41 +02:00
parent 24a7b2dbd3
commit 6448516aa0
2 changed files with 33 additions and 1 deletions

View File

@ -109,6 +109,38 @@ tap.test('should be able to delete an instance of car', async () => {
expect(myCar2.color).to.equal('red');
});
// tslint:disable-next-line: max-classes-per-file
@smartdata.Collection(() => {
return testDb;
})
class Truck extends smartdata.SmartDataDbDoc<Car> {
@smartdata.unI()
public id: string = smartunique.shortId();
@smartdata.svDb()
public color: string;
@smartdata.svDb()
public brand: string;
constructor(colorArg: string, brandArg: string) {
super();
this.color = colorArg;
this.brand = brandArg;
}
}
tap.test('should store a new Truck', async () => {
const truck = new Truck('blue', 'MAN');
await truck.save();
const myTruck = await Truck.getInstance<Truck>({color: 'blue'});
console.log(myTruck);
});
// =======================================
// close the database connection
// =======================================

View File

@ -113,7 +113,7 @@ export class SmartDataDbDoc<T> {
return returnArray;
}
static async getInstance<T>(filterArg): Promise<T> {
public static async getInstance<T>(filterArg): Promise<T> {
const result = await this.getInstances<T>(filterArg);
if (result && result.length > 0) {
return result[0];