import * as knex from 'knex' ; import { LockType } from '../enums/LockType' ; import { TableName } from '../enums/TableName' ; import { promisifyQuery } from '../utils/promisifyQuery' ; export class LockModel { public acquireLock ( db , userId , lockName ) { return new Promise ( async ( resolve , reject ) : Promise < void > => { try { await promisifyQuery ( db . raw ( `INSERT INTO ${ TableName . LOCK } (userId, lockName) VALUES (?, ?) ON DUPLICATE KEY UPDATE userId = VALUES(userId), lockName = VALUES(lockName)` , [ userId , lockName ] ) ) ; resolve ( ) ; } catch ( error ) { reject ( error ) ; } } ) ; } }