BindAudit.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const db = require('../../plugin/DataBase/db')
  2. const BindAuditAction = Object.freeze({
  3. PLATFORM_BIND: 'platform_bind',
  4. PLATFORM_UNBIND: 'platform_unbind',
  5. BOT_BIND: 'bot_bind',
  6. BOT_UNBIND: 'bot_unbind'
  7. })
  8. const BindAuditSource = Object.freeze({
  9. USER_API: 'user_api',
  10. ADMIN_API: 'admin_api',
  11. SERVICE_API: 'service_api',
  12. MCP_QQ: 'mcp_qq',
  13. MCP_WORK_ORDER: 'mcp_work_order'
  14. })
  15. async function insertBindAudit({
  16. studentNum,
  17. ownerUuid = null,
  18. action,
  19. source,
  20. operatorUuid = null,
  21. detail = null,
  22. createdAt = Date.now()
  23. }) {
  24. if (!studentNum || !action || !source) return false
  25. const sql = `
  26. INSERT INTO lepao_bind_audit
  27. (student_num, owner_uuid, action, source, operator_uuid, detail_json, created_at)
  28. VALUES (?, ?, ?, ?, ?, ?, ?)
  29. `
  30. const rows = await db.query(sql, [
  31. String(studentNum),
  32. ownerUuid || null,
  33. action,
  34. source,
  35. operatorUuid || null,
  36. detail ? JSON.stringify(detail) : null,
  37. Number(createdAt) || Date.now()
  38. ])
  39. return !!rows && rows.affectedRows === 1
  40. }
  41. module.exports = {
  42. BindAuditAction,
  43. BindAuditSource,
  44. insertBindAudit
  45. }