42 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-12-02 11:04:17 +08:00
import QbAddressDto from "../entity/dto/QbAddressDto";
2023-07-28 20:12:34 +08:00
import {tryLogin, updateQbInfo, getQbInfo} from '../util/QbApiUtil';
2022-12-02 11:04:17 +08:00
import GlobalConfigService from "./GlobalConfigService";
import GlobalConfig from "../entity/po/GlobalConfig";
class QbService {
2023-07-28 20:12:34 +08:00
/**
*
* @param body
*/
static async saveAddress(body: QbAddressDto): Promise<boolean> {
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbAddress", body.address, "qbAdress"));
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbUsername", body.username, ""));
await GlobalConfigService.insertOrReplace(new GlobalConfig("qbPassword", body.password, ""));
body.valid = await tryLogin();
updateQbInfo(body);
return body.valid;
}
/**
*
*/
static async getAddress(): Promise<QbAddressDto> {
return getQbInfo();
}
static async init() {
let config = await GlobalConfigService.getMultVal(["qbAddress", "qbUsername", "qbPassword"]);
let qbInfo: QbAddressDto = {
address: config.qbAddress,
username: config.qbUsername,
password: config.qbPassword,
valid: true
}
updateQbInfo(qbInfo);
qbInfo.valid = await tryLogin();
}
2022-12-02 11:04:17 +08:00
}
export default QbService;