来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
const path = require('path');
|
|
const serverRoot = path.join(__dirname, '..');
|
|
process.chdir(serverRoot);
|
|
require(path.join(serverRoot, 'dist/env.js')).loadEnv();
|
|
const jwt = require('jsonwebtoken');
|
|
const { pool } = require(path.join(serverRoot, 'dist/db.js'));
|
|
const { config } = require(path.join(serverRoot, 'dist/config.js'));
|
|
|
|
const supplierCode = process.argv[2] || 'SUP73639881';
|
|
|
|
(async () => {
|
|
const u = await pool.query(
|
|
`SELECT su.user_id, su.supplier_code, p.username, au.email
|
|
FROM supplier_users su
|
|
JOIN profiles p ON p.id = su.user_id
|
|
JOIN auth.users au ON au.id = su.user_id
|
|
WHERE su.supplier_code = $1 LIMIT 1`,
|
|
[supplierCode]
|
|
);
|
|
if (!u.rows[0]) {
|
|
console.error('No supplier user for', supplierCode);
|
|
process.exit(1);
|
|
}
|
|
const row = u.rows[0];
|
|
const token = jwt.sign(
|
|
{ sub: row.user_id, email: row.email, roleType: 'supplier', scope: 'mobile' },
|
|
config.jwtSecret,
|
|
{ expiresIn: '1h' }
|
|
);
|
|
|
|
const base = process.env.API_SELF_URL || 'http://127.0.0.1:3001';
|
|
for (const view of ['active', 'archived']) {
|
|
const url =
|
|
view === 'active'
|
|
? `${base}/api/mobile/supplier/preparations?view=active`
|
|
: `${base}/api/mobile/supplier/preparations?view=archived&date_from=2026-07-01&date_to=2026-07-09`;
|
|
const res = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
|
|
const body = await res.json();
|
|
console.log(`\n=== ${row.username} (${supplierCode}) view=${view} status=${res.status} ===`);
|
|
console.log('count:', body.data?.length ?? 'n/a');
|
|
if (body.error) console.log('error:', body.error, body.error_description);
|
|
if (body.data?.length) console.log('first:', body.data[0].item_name, body.data[0].task_day);
|
|
}
|
|
|
|
// Wrong role token test
|
|
const badToken = jwt.sign(
|
|
{ sub: row.user_id, email: row.email, roleType: 'purchaser', scope: 'mobile' },
|
|
config.jwtSecret,
|
|
{ expiresIn: '1h' }
|
|
);
|
|
const badRes = await fetch(`${base}/api/mobile/supplier/preparations?view=active`, {
|
|
headers: { Authorization: `Bearer ${badToken}` },
|
|
});
|
|
const badBody = await badRes.json();
|
|
console.log('\n=== wrong role (purchaser) ===');
|
|
console.log('status:', badRes.status, badBody.error_description || badBody.error);
|
|
|
|
await pool.end();
|
|
})().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|