为 miniprogram-ci 和 Jimp 依赖增加兼容 patch 与 smoke test;修复平台模板管理员路由漏配;收紧模板契约校验;为 admin/customer 增加 token 撤销和集中会话存储;同步品牌切换角色、doctor source hash、多屏宽截图证据和 CI 构建门禁。
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { BadRequestException, Injectable } from "@nestjs/common";
|
|
import { PrismaService } from "../../prisma.service.js";
|
|
import { signIdentity } from "../../auth.js";
|
|
import type { WechatSession } from "../../wechat-auth.js";
|
|
import { PublicBrandContextService } from "../public/public-brand-context.service.js";
|
|
|
|
@Injectable()
|
|
export class CustomerSessionService {
|
|
constructor(
|
|
private readonly prisma: PrismaService,
|
|
private readonly brandContext: PublicBrandContextService,
|
|
) {}
|
|
|
|
async loginWithWechat(session: WechatSession, brandSlug?: string): Promise<{ token: string }> {
|
|
const brandId = await this.brandContext.resolveId(brandSlug);
|
|
const brand = await this.prisma.brandProfile.findUnique({
|
|
where: { id: brandId },
|
|
select: { id: true },
|
|
});
|
|
if (!brand) throw new BadRequestException("品牌尚未初始化");
|
|
const customer = await this.prisma.customerUser.upsert({
|
|
where: { brandId_openid: { brandId: brand.id, openid: session.openid } },
|
|
update: { lastLoginAt: new Date() },
|
|
create: { brandId: brand.id, openid: session.openid },
|
|
});
|
|
return {
|
|
token: signIdentity({
|
|
subject: session.openid,
|
|
brandId: brand.id,
|
|
role: "customer",
|
|
tokenVersion: customer.tokenVersion,
|
|
}),
|
|
};
|
|
}
|
|
}
|