fix(experts): an expert edited in the panel now shows up in the app
The app shows a sales expert their own account through the linked trading Customer row (/customer/me). That row was seeded from the expert once, at first sign-in, and never updated again, so a name, mobile, credit-limit or wage-percent change made in the panel never reached the app. In the reference the agent and that account were one row, so an edit changed both. Editing an expert now mirrors exactly the changed fields onto the trading row in the same transaction: name parts, credit limit (gram_level), wage percent, and the mobile when no other customer holds it. Existing drift heals on the next save. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
600ce06d15
commit
ee43d664d5
+62
-9
@@ -101621,17 +101621,70 @@ var require_admin_users_service = __commonJS({
|
||||
}
|
||||
};
|
||||
}
|
||||
return this.prisma.adminUser.update({
|
||||
where: { id },
|
||||
data: patch,
|
||||
include: {
|
||||
userType: true,
|
||||
branch: true,
|
||||
avatarFile: true,
|
||||
salesExpertProfile: { include: { city: true } }
|
||||
}
|
||||
return this.prisma.$transaction(async (tx) => {
|
||||
const updated = await tx.adminUser.update({
|
||||
where: { id },
|
||||
data: patch,
|
||||
include: {
|
||||
userType: true,
|
||||
branch: true,
|
||||
avatarFile: true,
|
||||
salesExpertProfile: { include: { city: true } }
|
||||
}
|
||||
});
|
||||
await this.syncTradingAccount(tx, updated, existing.mobile, {
|
||||
name: patch.firstName !== void 0 || patch.lastName !== void 0 || patch.fullName !== void 0,
|
||||
mobile: patch.mobile !== void 0,
|
||||
gramLevel: data.gram_level !== void 0,
|
||||
percent: data.percent !== void 0
|
||||
});
|
||||
return updated;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Mirror an expert edit onto their trading Customer row (D21).
|
||||
*
|
||||
* The apps show an expert their OWN account through that row (/customer/me),
|
||||
* which is seeded from the expert once, at first sign-in, and was never
|
||||
* updated again — so a name or credit-limit change made here never reached
|
||||
* the app. In the reference the agent and that account were ONE row
|
||||
* (customers.type=1), so an edit changed both; this restores that.
|
||||
*
|
||||
* Only the fields the operator actually changed are written. The mobile is
|
||||
* copied only when no other customer holds it (the column is unique);
|
||||
* otherwise it is left and logged rather than failing the expert's save.
|
||||
*/
|
||||
async syncTradingAccount(tx, expert, previousMobile, changed) {
|
||||
const tradingId = expert.salesExpertProfile?.tradingCustomerId;
|
||||
if (!tradingId)
|
||||
return;
|
||||
const data = {};
|
||||
if (changed.name) {
|
||||
if (expert.firstName !== null || expert.lastName !== null) {
|
||||
data.firstName = expert.firstName;
|
||||
data.lastName = expert.lastName;
|
||||
} else {
|
||||
data.fullName = expert.fullName;
|
||||
}
|
||||
}
|
||||
if (changed.mobile && expert.mobile !== previousMobile) {
|
||||
const holder = await tx.customer.findUnique({ where: { mobile: expert.mobile }, select: { id: true } });
|
||||
if (!holder) {
|
||||
data.mobile = expert.mobile;
|
||||
} else if (holder.id !== tradingId) {
|
||||
this.logger.warn(`Expert ${expert.id}: new mobile ${expert.mobile} already belongs to customer ${holder.id}; trading account ${tradingId} keeps its old mobile.`);
|
||||
}
|
||||
}
|
||||
if (changed.gramLevel && expert.salesExpertProfile) {
|
||||
data.goldCreditLimitGrams = expert.salesExpertProfile.gramLevel;
|
||||
}
|
||||
if (changed.percent) {
|
||||
data.makingChargeOffsetPercent = expert.wagePercent ?? new client_1.Prisma.Decimal(0);
|
||||
}
|
||||
if (Object.keys(data).length > 0) {
|
||||
await tx.customer.update({ where: { id: tradingId }, data });
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Legacy `DELETE users/{id}`.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user