add findOne to db

This commit is contained in:
Jiiks 2018-08-20 02:38:17 +03:00
parent beaee8764c
commit 205dcf6ff1
1 changed files with 15 additions and 0 deletions

View File

@ -43,4 +43,19 @@ export default class {
}
}
/**
* Find first in the database
* @param {Object} args The record to find
* @return {Promise} null if record was not found
*/
static async findOne(args) {
try {
const find = await this.find(args);
if (find && find.length) return find[0];
return null;
} catch (err) {
throw err;
}
}
}