UNPKG

pockybot

Version:

Spark bot that handles team recognition

83 lines (82 loc) 3.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class DbLocation { constructor(queryHandler) { this.queryHandler = queryHandler; this.sqlGetUserLocation = this.queryHandler.readFile('../../../database/queries/get_user_location.sql'); this.sqlGetAllUserLocations = this.queryHandler.readFile('../../../database/queries/get_all_user_locations.sql'); this.sqlGetLocations = this.queryHandler.readFile('../../../database/queries/get_locations.sql'); this.sqlGetUsersWithoutLocation = this.queryHandler.readFile('../../../database/queries/get_users_without_location.sql'); this.sqlSetUserLocation = this.queryHandler.readFile('../../../database/queries/set_user_location.sql'); this.sqlSetLocation = this.queryHandler.readFile('../../../database/queries/set_location.sql'); this.sqlDeleteUserLocation = this.queryHandler.readFile('../../../database/queries/delete_user_location.sql'); this.sqlDeleteLocation = this.queryHandler.readFile('../../../database/queries/delete_location.sql'); } async getUserLocation(userid) { let query = { name: 'getUserLocationQuery', text: this.sqlGetUserLocation, values: [userid] }; let result = await this.queryHandler.executeQuery(query); return result[0]; } async getAllUserLocations() { let query = { name: 'getAllUserLocationsQuery', text: this.sqlGetAllUserLocations, values: [] }; return await this.queryHandler.executeQuery(query); } async getLocations() { let query = { name: 'getLocationsQuery', text: this.sqlGetLocations, values: [] }; let result = await this.queryHandler.executeQuery(query); return result.map(x => x.name); } async getUsersWithoutLocation() { let query = { name: 'getUsersWithoutLocationQuery', text: this.sqlGetUsersWithoutLocation, values: [] }; return await this.queryHandler.executeQuery(query); } async setUserLocation(userid, location) { let query = { name: 'setUserLocationQuery', text: this.sqlSetUserLocation, values: [userid, location] }; await this.queryHandler.executeNonQuery(query); } async setLocation(name) { let query = { name: 'setLocationQuery', text: this.sqlSetLocation, values: [name] }; await this.queryHandler.executeNonQuery(query); } async deleteUserLocation(userid) { let query = { name: 'deleteUserLocationQuery', text: this.sqlDeleteUserLocation, values: [userid] }; await this.queryHandler.executeNonQuery(query); } async deleteLocation(name) { let query = { name: 'deleteLocationQuery', text: this.sqlDeleteLocation, values: [name] }; await this.queryHandler.executeNonQuery(query); } } exports.default = DbLocation;