Synchronize material statuses by setting MaterialStatus::Off in card info scripts and adding state enforcement logic to postMaterial in NetworkService.
This commit is contained in:
parent
98f1d0f9d6
commit
ff4a468b35
@ -119,7 +119,7 @@ void GetCardInfoScript::doStart() {
|
||||
account.amount = balance;
|
||||
account.currency = "ARS";
|
||||
account.description = "CVU";
|
||||
account.status = MaterialStatus::Active;
|
||||
account.status = MaterialStatus::Off;
|
||||
account.updateTime = QDateTime::currentDateTimeUtc();
|
||||
|
||||
if (!MaterialDAO::upsertAccount(account)) {
|
||||
|
||||
@ -248,7 +248,7 @@ void GetCardInfoScript::doStart() {
|
||||
account.amount = cardBalance;
|
||||
account.currency = "TJS";
|
||||
account.description = cards[i].description.isEmpty() ? holder : cards[i].description;
|
||||
account.status = MaterialStatus::Active;
|
||||
account.status = MaterialStatus::Off;
|
||||
account.updateTime = QDateTime::currentDateTimeUtc();
|
||||
|
||||
qDebug() << "[Dushanbe::GetCardInfo] Saving card:" << "lastNumbers=" << lastNumbers
|
||||
|
||||
@ -157,7 +157,7 @@ void GetCardInfoScript::doStart() {
|
||||
card.deviceId = device.id;
|
||||
card.appCode = m_appCode;
|
||||
card.updateTime = QDateTime::currentDateTimeUtc();
|
||||
card.status = MaterialStatus::Active;
|
||||
card.status = MaterialStatus::Off;
|
||||
if (!MaterialDAO::upsertAccount(card)) {
|
||||
qWarning() << "[GetCardInfo] Failed to upsert account for card" << card.lastNumbers;
|
||||
} else {
|
||||
|
||||
@ -1126,6 +1126,23 @@ void NetworkService::postMaterial() {
|
||||
MaterialDAO::updateMaterialId(accountId, materialId);
|
||||
}
|
||||
qDebug() << "[NetworkService] postMaterial ok, card:" << body["card_number"].toString() << "material_id:" << materialId;
|
||||
|
||||
// Сервер не применяет поле state при POST — отдельный PATCH /<id>/<true|false>.
|
||||
if (!materialId.isEmpty()) {
|
||||
const QString state = body.value("state").toString();
|
||||
if (!state.isEmpty()) {
|
||||
const QString enableStr = (state == "enabled") ? "true" : "false";
|
||||
const QString togglePath = m_apiBase + m_pathMaterial + "/" + materialId + "/" + enableStr;
|
||||
const QJsonValue toggleResult = patchJson(togglePath, QJsonObject(), true);
|
||||
if (toggleResult.isNull() || toggleResult.isUndefined()) {
|
||||
qWarning() << "[NetworkService] postMaterial: state enforcement failed for"
|
||||
<< materialId << "state=" << state;
|
||||
} else {
|
||||
qDebug() << "[NetworkService] postMaterial: state enforced for"
|
||||
<< materialId << "state=" << state;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit finished();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user