2955 lines
62 KiB
JavaScript
2955 lines
62 KiB
JavaScript
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Departments = db.departments;
|
|
|
|
const Requests = db.requests;
|
|
|
|
const RequestApprovals = db.request_approvals;
|
|
|
|
const Documents = db.documents;
|
|
|
|
const DocumentIntakes = db.document_intakes;
|
|
|
|
const AuditEvents = db.audit_events;
|
|
|
|
const SystemSettings = db.system_settings;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const DepartmentsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"code": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"requires_director_approval": false,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"code": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"requires_director_approval": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"code": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"requires_director_approval": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const RequestsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"request_number": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"priority": "low",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "restarted",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"requires_director": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"submitted_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"finalized_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"restart_count": 5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"rejection_reason": "Marie Curie",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"request_number": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"priority": "urgent",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "draft",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"requires_director": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"submitted_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"finalized_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"restart_count": 8,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"rejection_reason": "Alan Turing",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"request_number": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"priority": "high",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "in_review",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"requires_director": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"submitted_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"finalized_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"restart_count": 7,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"rejection_reason": "Alan Turing",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const RequestApprovalsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"step": "director",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"decision": "pending",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"decided_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"comment": "Marie Curie",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"step": "admin_override",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"decision": "overridden",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"decided_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"comment": "Alan Turing",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"step": "supervisor_hod",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"decision": "approved",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"decided_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"comment": "Grace Hopper",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const DocumentsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"document_number": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"document_type": "request_attachment",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"original_filename": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"mime_type": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"file_size_bytes": 6,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"checksum_sha256": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"visibility": "department",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"uploaded_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"document_number": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"document_type": "request_attachment",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"original_filename": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"mime_type": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"file_size_bytes": 9,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"checksum_sha256": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"visibility": "department",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"uploaded_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"document_number": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"document_type": "supporting_document",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"original_filename": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"mime_type": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"file_size_bytes": 2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"checksum_sha256": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"visibility": "department",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"uploaded_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_active": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const DocumentIntakesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"intake_number": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"intake_status": "sent_to_department",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"notes": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"received_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"intake_number": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"intake_status": "scanned",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"notes": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"received_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"intake_number": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"intake_status": "sent_to_department",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"notes": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"received_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const AuditEventsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"entity_type": "document_intake",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entity_key": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"action": "reject",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"summary": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"details": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"event_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Alan Turing",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"entity_type": "document",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entity_key": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"action": "reject",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"summary": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"details": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"event_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Marie Curie",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"entity_type": "document",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entity_key": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"action": "login",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"summary": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"details": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"event_at": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Ada Lovelace",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const SystemSettingsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"site_name": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"header_html": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"footer_html": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"theme_name": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"support_email": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"effective_from": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_current": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"site_name": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"header_html": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"footer_html": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"theme_name": "Ada Lovelace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"support_email": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"effective_from": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_current": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"site_name": "Marie Curie",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"header_html": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"footer_html": "Grace Hopper",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"theme_name": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"support_email": "Alan Turing",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"effective_from": new Date(Date.now()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_current": false,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateDepartmentWithSupervisor_user() {
|
|
|
|
const relatedSupervisor_user0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Department0 = await Departments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Department0?.setSupervisor_user)
|
|
{
|
|
await
|
|
Department0.
|
|
setSupervisor_user(relatedSupervisor_user0);
|
|
}
|
|
|
|
const relatedSupervisor_user1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Department1 = await Departments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Department1?.setSupervisor_user)
|
|
{
|
|
await
|
|
Department1.
|
|
setSupervisor_user(relatedSupervisor_user1);
|
|
}
|
|
|
|
const relatedSupervisor_user2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Department2 = await Departments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Department2?.setSupervisor_user)
|
|
{
|
|
await
|
|
Department2.
|
|
setSupervisor_user(relatedSupervisor_user2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateDepartmentWithDirector_user() {
|
|
|
|
const relatedDirector_user0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Department0 = await Departments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Department0?.setDirector_user)
|
|
{
|
|
await
|
|
Department0.
|
|
setDirector_user(relatedDirector_user0);
|
|
}
|
|
|
|
const relatedDirector_user1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Department1 = await Departments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Department1?.setDirector_user)
|
|
{
|
|
await
|
|
Department1.
|
|
setDirector_user(relatedDirector_user1);
|
|
}
|
|
|
|
const relatedDirector_user2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Department2 = await Departments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Department2?.setDirector_user)
|
|
{
|
|
await
|
|
Department2.
|
|
setDirector_user(relatedDirector_user2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateRequestWithRequester() {
|
|
|
|
const relatedRequester0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Request0 = await Requests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Request0?.setRequester)
|
|
{
|
|
await
|
|
Request0.
|
|
setRequester(relatedRequester0);
|
|
}
|
|
|
|
const relatedRequester1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Request1 = await Requests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Request1?.setRequester)
|
|
{
|
|
await
|
|
Request1.
|
|
setRequester(relatedRequester1);
|
|
}
|
|
|
|
const relatedRequester2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Request2 = await Requests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Request2?.setRequester)
|
|
{
|
|
await
|
|
Request2.
|
|
setRequester(relatedRequester2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateRequestWithOrigin_department() {
|
|
|
|
const relatedOrigin_department0 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const Request0 = await Requests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Request0?.setOrigin_department)
|
|
{
|
|
await
|
|
Request0.
|
|
setOrigin_department(relatedOrigin_department0);
|
|
}
|
|
|
|
const relatedOrigin_department1 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const Request1 = await Requests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Request1?.setOrigin_department)
|
|
{
|
|
await
|
|
Request1.
|
|
setOrigin_department(relatedOrigin_department1);
|
|
}
|
|
|
|
const relatedOrigin_department2 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const Request2 = await Requests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Request2?.setOrigin_department)
|
|
{
|
|
await
|
|
Request2.
|
|
setOrigin_department(relatedOrigin_department2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateRequestWithAssigned_department() {
|
|
|
|
const relatedAssigned_department0 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const Request0 = await Requests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Request0?.setAssigned_department)
|
|
{
|
|
await
|
|
Request0.
|
|
setAssigned_department(relatedAssigned_department0);
|
|
}
|
|
|
|
const relatedAssigned_department1 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const Request1 = await Requests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Request1?.setAssigned_department)
|
|
{
|
|
await
|
|
Request1.
|
|
setAssigned_department(relatedAssigned_department1);
|
|
}
|
|
|
|
const relatedAssigned_department2 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const Request2 = await Requests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Request2?.setAssigned_department)
|
|
{
|
|
await
|
|
Request2.
|
|
setAssigned_department(relatedAssigned_department2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateRequestApprovalWithRequest() {
|
|
|
|
const relatedRequest0 = await Requests.findOne({
|
|
offset: Math.floor(Math.random() * (await Requests.count())),
|
|
});
|
|
const RequestApproval0 = await RequestApprovals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (RequestApproval0?.setRequest)
|
|
{
|
|
await
|
|
RequestApproval0.
|
|
setRequest(relatedRequest0);
|
|
}
|
|
|
|
const relatedRequest1 = await Requests.findOne({
|
|
offset: Math.floor(Math.random() * (await Requests.count())),
|
|
});
|
|
const RequestApproval1 = await RequestApprovals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (RequestApproval1?.setRequest)
|
|
{
|
|
await
|
|
RequestApproval1.
|
|
setRequest(relatedRequest1);
|
|
}
|
|
|
|
const relatedRequest2 = await Requests.findOne({
|
|
offset: Math.floor(Math.random() * (await Requests.count())),
|
|
});
|
|
const RequestApproval2 = await RequestApprovals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (RequestApproval2?.setRequest)
|
|
{
|
|
await
|
|
RequestApproval2.
|
|
setRequest(relatedRequest2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateRequestApprovalWithDecided_by() {
|
|
|
|
const relatedDecided_by0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const RequestApproval0 = await RequestApprovals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (RequestApproval0?.setDecided_by)
|
|
{
|
|
await
|
|
RequestApproval0.
|
|
setDecided_by(relatedDecided_by0);
|
|
}
|
|
|
|
const relatedDecided_by1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const RequestApproval1 = await RequestApprovals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (RequestApproval1?.setDecided_by)
|
|
{
|
|
await
|
|
RequestApproval1.
|
|
setDecided_by(relatedDecided_by1);
|
|
}
|
|
|
|
const relatedDecided_by2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const RequestApproval2 = await RequestApprovals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (RequestApproval2?.setDecided_by)
|
|
{
|
|
await
|
|
RequestApproval2.
|
|
setDecided_by(relatedDecided_by2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateDocumentWithUploaded_by_user() {
|
|
|
|
const relatedUploaded_by_user0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Document0 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Document0?.setUploaded_by_user)
|
|
{
|
|
await
|
|
Document0.
|
|
setUploaded_by_user(relatedUploaded_by_user0);
|
|
}
|
|
|
|
const relatedUploaded_by_user1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Document1 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Document1?.setUploaded_by_user)
|
|
{
|
|
await
|
|
Document1.
|
|
setUploaded_by_user(relatedUploaded_by_user1);
|
|
}
|
|
|
|
const relatedUploaded_by_user2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Document2 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Document2?.setUploaded_by_user)
|
|
{
|
|
await
|
|
Document2.
|
|
setUploaded_by_user(relatedUploaded_by_user2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateDocumentWithRequest() {
|
|
|
|
const relatedRequest0 = await Requests.findOne({
|
|
offset: Math.floor(Math.random() * (await Requests.count())),
|
|
});
|
|
const Document0 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Document0?.setRequest)
|
|
{
|
|
await
|
|
Document0.
|
|
setRequest(relatedRequest0);
|
|
}
|
|
|
|
const relatedRequest1 = await Requests.findOne({
|
|
offset: Math.floor(Math.random() * (await Requests.count())),
|
|
});
|
|
const Document1 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Document1?.setRequest)
|
|
{
|
|
await
|
|
Document1.
|
|
setRequest(relatedRequest1);
|
|
}
|
|
|
|
const relatedRequest2 = await Requests.findOne({
|
|
offset: Math.floor(Math.random() * (await Requests.count())),
|
|
});
|
|
const Document2 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Document2?.setRequest)
|
|
{
|
|
await
|
|
Document2.
|
|
setRequest(relatedRequest2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateDocumentWithIntake_record() {
|
|
|
|
const relatedIntake_record0 = await DocumentIntakes.findOne({
|
|
offset: Math.floor(Math.random() * (await DocumentIntakes.count())),
|
|
});
|
|
const Document0 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Document0?.setIntake_record)
|
|
{
|
|
await
|
|
Document0.
|
|
setIntake_record(relatedIntake_record0);
|
|
}
|
|
|
|
const relatedIntake_record1 = await DocumentIntakes.findOne({
|
|
offset: Math.floor(Math.random() * (await DocumentIntakes.count())),
|
|
});
|
|
const Document1 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Document1?.setIntake_record)
|
|
{
|
|
await
|
|
Document1.
|
|
setIntake_record(relatedIntake_record1);
|
|
}
|
|
|
|
const relatedIntake_record2 = await DocumentIntakes.findOne({
|
|
offset: Math.floor(Math.random() * (await DocumentIntakes.count())),
|
|
});
|
|
const Document2 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Document2?.setIntake_record)
|
|
{
|
|
await
|
|
Document2.
|
|
setIntake_record(relatedIntake_record2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateDocumentIntakeWithReceived_by_user() {
|
|
|
|
const relatedReceived_by_user0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const DocumentIntake0 = await DocumentIntakes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (DocumentIntake0?.setReceived_by_user)
|
|
{
|
|
await
|
|
DocumentIntake0.
|
|
setReceived_by_user(relatedReceived_by_user0);
|
|
}
|
|
|
|
const relatedReceived_by_user1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const DocumentIntake1 = await DocumentIntakes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (DocumentIntake1?.setReceived_by_user)
|
|
{
|
|
await
|
|
DocumentIntake1.
|
|
setReceived_by_user(relatedReceived_by_user1);
|
|
}
|
|
|
|
const relatedReceived_by_user2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const DocumentIntake2 = await DocumentIntakes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (DocumentIntake2?.setReceived_by_user)
|
|
{
|
|
await
|
|
DocumentIntake2.
|
|
setReceived_by_user(relatedReceived_by_user2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateDocumentIntakeWithReceived_from_department() {
|
|
|
|
const relatedReceived_from_department0 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const DocumentIntake0 = await DocumentIntakes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (DocumentIntake0?.setReceived_from_department)
|
|
{
|
|
await
|
|
DocumentIntake0.
|
|
setReceived_from_department(relatedReceived_from_department0);
|
|
}
|
|
|
|
const relatedReceived_from_department1 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const DocumentIntake1 = await DocumentIntakes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (DocumentIntake1?.setReceived_from_department)
|
|
{
|
|
await
|
|
DocumentIntake1.
|
|
setReceived_from_department(relatedReceived_from_department1);
|
|
}
|
|
|
|
const relatedReceived_from_department2 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const DocumentIntake2 = await DocumentIntakes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (DocumentIntake2?.setReceived_from_department)
|
|
{
|
|
await
|
|
DocumentIntake2.
|
|
setReceived_from_department(relatedReceived_from_department2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateDocumentIntakeWithTarget_department() {
|
|
|
|
const relatedTarget_department0 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const DocumentIntake0 = await DocumentIntakes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (DocumentIntake0?.setTarget_department)
|
|
{
|
|
await
|
|
DocumentIntake0.
|
|
setTarget_department(relatedTarget_department0);
|
|
}
|
|
|
|
const relatedTarget_department1 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const DocumentIntake1 = await DocumentIntakes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (DocumentIntake1?.setTarget_department)
|
|
{
|
|
await
|
|
DocumentIntake1.
|
|
setTarget_department(relatedTarget_department1);
|
|
}
|
|
|
|
const relatedTarget_department2 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const DocumentIntake2 = await DocumentIntakes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (DocumentIntake2?.setTarget_department)
|
|
{
|
|
await
|
|
DocumentIntake2.
|
|
setTarget_department(relatedTarget_department2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateAuditEventWithActor() {
|
|
|
|
const relatedActor0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const AuditEvent0 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (AuditEvent0?.setActor)
|
|
{
|
|
await
|
|
AuditEvent0.
|
|
setActor(relatedActor0);
|
|
}
|
|
|
|
const relatedActor1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const AuditEvent1 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (AuditEvent1?.setActor)
|
|
{
|
|
await
|
|
AuditEvent1.
|
|
setActor(relatedActor1);
|
|
}
|
|
|
|
const relatedActor2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const AuditEvent2 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (AuditEvent2?.setActor)
|
|
{
|
|
await
|
|
AuditEvent2.
|
|
setActor(relatedActor2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateAuditEventWithFrom_department() {
|
|
|
|
const relatedFrom_department0 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const AuditEvent0 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (AuditEvent0?.setFrom_department)
|
|
{
|
|
await
|
|
AuditEvent0.
|
|
setFrom_department(relatedFrom_department0);
|
|
}
|
|
|
|
const relatedFrom_department1 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const AuditEvent1 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (AuditEvent1?.setFrom_department)
|
|
{
|
|
await
|
|
AuditEvent1.
|
|
setFrom_department(relatedFrom_department1);
|
|
}
|
|
|
|
const relatedFrom_department2 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const AuditEvent2 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (AuditEvent2?.setFrom_department)
|
|
{
|
|
await
|
|
AuditEvent2.
|
|
setFrom_department(relatedFrom_department2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateAuditEventWithTo_department() {
|
|
|
|
const relatedTo_department0 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const AuditEvent0 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (AuditEvent0?.setTo_department)
|
|
{
|
|
await
|
|
AuditEvent0.
|
|
setTo_department(relatedTo_department0);
|
|
}
|
|
|
|
const relatedTo_department1 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const AuditEvent1 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (AuditEvent1?.setTo_department)
|
|
{
|
|
await
|
|
AuditEvent1.
|
|
setTo_department(relatedTo_department1);
|
|
}
|
|
|
|
const relatedTo_department2 = await Departments.findOne({
|
|
offset: Math.floor(Math.random() * (await Departments.count())),
|
|
});
|
|
const AuditEvent2 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (AuditEvent2?.setTo_department)
|
|
{
|
|
await
|
|
AuditEvent2.
|
|
setTo_department(relatedTo_department2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateAuditEventWithRelated_document() {
|
|
|
|
const relatedRelated_document0 = await Documents.findOne({
|
|
offset: Math.floor(Math.random() * (await Documents.count())),
|
|
});
|
|
const AuditEvent0 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (AuditEvent0?.setRelated_document)
|
|
{
|
|
await
|
|
AuditEvent0.
|
|
setRelated_document(relatedRelated_document0);
|
|
}
|
|
|
|
const relatedRelated_document1 = await Documents.findOne({
|
|
offset: Math.floor(Math.random() * (await Documents.count())),
|
|
});
|
|
const AuditEvent1 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (AuditEvent1?.setRelated_document)
|
|
{
|
|
await
|
|
AuditEvent1.
|
|
setRelated_document(relatedRelated_document1);
|
|
}
|
|
|
|
const relatedRelated_document2 = await Documents.findOne({
|
|
offset: Math.floor(Math.random() * (await Documents.count())),
|
|
});
|
|
const AuditEvent2 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (AuditEvent2?.setRelated_document)
|
|
{
|
|
await
|
|
AuditEvent2.
|
|
setRelated_document(relatedRelated_document2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateAuditEventWithRelated_request() {
|
|
|
|
const relatedRelated_request0 = await Requests.findOne({
|
|
offset: Math.floor(Math.random() * (await Requests.count())),
|
|
});
|
|
const AuditEvent0 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (AuditEvent0?.setRelated_request)
|
|
{
|
|
await
|
|
AuditEvent0.
|
|
setRelated_request(relatedRelated_request0);
|
|
}
|
|
|
|
const relatedRelated_request1 = await Requests.findOne({
|
|
offset: Math.floor(Math.random() * (await Requests.count())),
|
|
});
|
|
const AuditEvent1 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (AuditEvent1?.setRelated_request)
|
|
{
|
|
await
|
|
AuditEvent1.
|
|
setRelated_request(relatedRelated_request1);
|
|
}
|
|
|
|
const relatedRelated_request2 = await Requests.findOne({
|
|
offset: Math.floor(Math.random() * (await Requests.count())),
|
|
});
|
|
const AuditEvent2 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (AuditEvent2?.setRelated_request)
|
|
{
|
|
await
|
|
AuditEvent2.
|
|
setRelated_request(relatedRelated_request2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Departments.bulkCreate(DepartmentsData);
|
|
|
|
|
|
|
|
|
|
await Requests.bulkCreate(RequestsData);
|
|
|
|
|
|
|
|
|
|
await RequestApprovals.bulkCreate(RequestApprovalsData);
|
|
|
|
|
|
|
|
|
|
await Documents.bulkCreate(DocumentsData);
|
|
|
|
|
|
|
|
|
|
await DocumentIntakes.bulkCreate(DocumentIntakesData);
|
|
|
|
|
|
|
|
|
|
await AuditEvents.bulkCreate(AuditEventsData);
|
|
|
|
|
|
|
|
|
|
await SystemSettings.bulkCreate(SystemSettingsData);
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateDepartmentWithSupervisor_user(),
|
|
|
|
|
|
|
|
|
|
await associateDepartmentWithDirector_user(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateRequestWithRequester(),
|
|
|
|
|
|
|
|
|
|
await associateRequestWithOrigin_department(),
|
|
|
|
|
|
|
|
|
|
await associateRequestWithAssigned_department(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateRequestApprovalWithRequest(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateRequestApprovalWithDecided_by(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateDocumentWithUploaded_by_user(),
|
|
|
|
|
|
|
|
|
|
await associateDocumentWithRequest(),
|
|
|
|
|
|
|
|
|
|
await associateDocumentWithIntake_record(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateDocumentIntakeWithReceived_by_user(),
|
|
|
|
|
|
|
|
|
|
await associateDocumentIntakeWithReceived_from_department(),
|
|
|
|
|
|
|
|
|
|
await associateDocumentIntakeWithTarget_department(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateAuditEventWithActor(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateAuditEventWithFrom_department(),
|
|
|
|
|
|
|
|
|
|
await associateAuditEventWithTo_department(),
|
|
|
|
|
|
|
|
|
|
await associateAuditEventWithRelated_document(),
|
|
|
|
|
|
|
|
|
|
await associateAuditEventWithRelated_request(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await queryInterface.bulkDelete('departments', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('requests', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('request_approvals', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('documents', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('document_intakes', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('audit_events', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('system_settings', null, {});
|
|
|
|
|
|
},
|
|
}; |