@hasna/microservices 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +9 -1
- package/bin/mcp.js +9 -1
- package/dist/index.js +9 -1
- package/microservices/microservice-ads/src/cli/index.ts +198 -0
- package/microservices/microservice-ads/src/db/campaigns.ts +304 -0
- package/microservices/microservice-ads/src/mcp/index.ts +160 -0
- package/microservices/microservice-company/package.json +27 -0
- package/microservices/microservice-company/src/cli/index.ts +1126 -0
- package/microservices/microservice-company/src/db/company.ts +854 -0
- package/microservices/microservice-company/src/db/database.ts +93 -0
- package/microservices/microservice-company/src/db/migrations.ts +214 -0
- package/microservices/microservice-company/src/db/workflow-migrations.ts +44 -0
- package/microservices/microservice-company/src/index.ts +60 -0
- package/microservices/microservice-company/src/lib/audit.ts +168 -0
- package/microservices/microservice-company/src/lib/finance.ts +299 -0
- package/microservices/microservice-company/src/lib/settings.ts +85 -0
- package/microservices/microservice-company/src/lib/workflows.ts +698 -0
- package/microservices/microservice-company/src/mcp/index.ts +991 -0
- package/microservices/microservice-contracts/src/cli/index.ts +410 -23
- package/microservices/microservice-contracts/src/db/contracts.ts +430 -1
- package/microservices/microservice-contracts/src/db/migrations.ts +83 -0
- package/microservices/microservice-contracts/src/mcp/index.ts +312 -3
- package/microservices/microservice-domains/src/cli/index.ts +673 -0
- package/microservices/microservice-domains/src/db/domains.ts +613 -0
- package/microservices/microservice-domains/src/index.ts +21 -0
- package/microservices/microservice-domains/src/lib/brandsight.ts +285 -0
- package/microservices/microservice-domains/src/lib/godaddy.ts +328 -0
- package/microservices/microservice-domains/src/lib/namecheap.ts +474 -0
- package/microservices/microservice-domains/src/lib/registrar.ts +355 -0
- package/microservices/microservice-domains/src/mcp/index.ts +413 -0
- package/microservices/microservice-hiring/src/cli/index.ts +318 -8
- package/microservices/microservice-hiring/src/db/hiring.ts +503 -0
- package/microservices/microservice-hiring/src/db/migrations.ts +21 -0
- package/microservices/microservice-hiring/src/index.ts +29 -0
- package/microservices/microservice-hiring/src/lib/scoring.ts +206 -0
- package/microservices/microservice-hiring/src/mcp/index.ts +245 -0
- package/microservices/microservice-payments/src/cli/index.ts +255 -3
- package/microservices/microservice-payments/src/db/migrations.ts +18 -0
- package/microservices/microservice-payments/src/db/payments.ts +552 -0
- package/microservices/microservice-payments/src/mcp/index.ts +223 -0
- package/microservices/microservice-payroll/src/cli/index.ts +269 -0
- package/microservices/microservice-payroll/src/db/migrations.ts +26 -0
- package/microservices/microservice-payroll/src/db/payroll.ts +636 -0
- package/microservices/microservice-payroll/src/mcp/index.ts +246 -0
- package/microservices/microservice-shipping/src/cli/index.ts +211 -3
- package/microservices/microservice-shipping/src/db/migrations.ts +8 -0
- package/microservices/microservice-shipping/src/db/shipping.ts +453 -3
- package/microservices/microservice-shipping/src/mcp/index.ts +149 -1
- package/microservices/microservice-social/src/cli/index.ts +244 -2
- package/microservices/microservice-social/src/db/migrations.ts +33 -0
- package/microservices/microservice-social/src/db/social.ts +378 -4
- package/microservices/microservice-social/src/mcp/index.ts +221 -1
- package/microservices/microservice-subscriptions/src/cli/index.ts +315 -0
- package/microservices/microservice-subscriptions/src/db/migrations.ts +68 -0
- package/microservices/microservice-subscriptions/src/db/subscriptions.ts +567 -3
- package/microservices/microservice-subscriptions/src/mcp/index.ts +267 -1
- package/package.json +1 -1
|
@@ -580,3 +580,506 @@ export function deleteInterview(id: string): boolean {
|
|
|
580
580
|
const result = db.prepare("DELETE FROM interviews WHERE id = ?").run(id);
|
|
581
581
|
return result.changes > 0;
|
|
582
582
|
}
|
|
583
|
+
|
|
584
|
+
// ---- Bulk Import ----
|
|
585
|
+
|
|
586
|
+
export interface BulkImportResult {
|
|
587
|
+
imported: number;
|
|
588
|
+
skipped: number;
|
|
589
|
+
errors: string[];
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
export function bulkImportApplicants(csvData: string): BulkImportResult {
|
|
593
|
+
const lines = csvData.trim().split("\n");
|
|
594
|
+
if (lines.length < 2) {
|
|
595
|
+
return { imported: 0, skipped: 0, errors: ["CSV must have a header row and at least one data row"] };
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
const header = lines[0].split(",").map((h) => h.trim().toLowerCase());
|
|
599
|
+
const requiredCols = ["name"];
|
|
600
|
+
for (const col of requiredCols) {
|
|
601
|
+
if (!header.includes(col)) {
|
|
602
|
+
return { imported: 0, skipped: 0, errors: [`Missing required column: ${col}`] };
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const nameIdx = header.indexOf("name");
|
|
607
|
+
const emailIdx = header.indexOf("email");
|
|
608
|
+
const phoneIdx = header.indexOf("phone");
|
|
609
|
+
const jobIdIdx = header.indexOf("job_id");
|
|
610
|
+
const sourceIdx = header.indexOf("source");
|
|
611
|
+
const resumeUrlIdx = header.indexOf("resume_url");
|
|
612
|
+
|
|
613
|
+
let imported = 0;
|
|
614
|
+
let skipped = 0;
|
|
615
|
+
const errors: string[] = [];
|
|
616
|
+
|
|
617
|
+
for (let i = 1; i < lines.length; i++) {
|
|
618
|
+
const line = lines[i].trim();
|
|
619
|
+
if (!line) { skipped++; continue; }
|
|
620
|
+
|
|
621
|
+
const cols = parseCsvLine(line);
|
|
622
|
+
const name = cols[nameIdx]?.trim();
|
|
623
|
+
|
|
624
|
+
if (!name) {
|
|
625
|
+
errors.push(`Row ${i + 1}: missing name`);
|
|
626
|
+
skipped++;
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const jobId = jobIdIdx >= 0 ? cols[jobIdIdx]?.trim() : undefined;
|
|
631
|
+
if (!jobId) {
|
|
632
|
+
errors.push(`Row ${i + 1}: missing job_id`);
|
|
633
|
+
skipped++;
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// Verify job exists
|
|
638
|
+
const job = getJob(jobId);
|
|
639
|
+
if (!job) {
|
|
640
|
+
errors.push(`Row ${i + 1}: job '${jobId}' not found`);
|
|
641
|
+
skipped++;
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
try {
|
|
646
|
+
createApplicant({
|
|
647
|
+
name,
|
|
648
|
+
job_id: jobId,
|
|
649
|
+
email: emailIdx >= 0 ? cols[emailIdx]?.trim() || undefined : undefined,
|
|
650
|
+
phone: phoneIdx >= 0 ? cols[phoneIdx]?.trim() || undefined : undefined,
|
|
651
|
+
source: sourceIdx >= 0 ? cols[sourceIdx]?.trim() || undefined : undefined,
|
|
652
|
+
resume_url: resumeUrlIdx >= 0 ? cols[resumeUrlIdx]?.trim() || undefined : undefined,
|
|
653
|
+
});
|
|
654
|
+
imported++;
|
|
655
|
+
} catch (err) {
|
|
656
|
+
errors.push(`Row ${i + 1}: ${err instanceof Error ? err.message : String(err)}`);
|
|
657
|
+
skipped++;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return { imported, skipped, errors };
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/** Simple CSV line parser that handles quoted fields */
|
|
665
|
+
function parseCsvLine(line: string): string[] {
|
|
666
|
+
const result: string[] = [];
|
|
667
|
+
let current = "";
|
|
668
|
+
let inQuotes = false;
|
|
669
|
+
|
|
670
|
+
for (let i = 0; i < line.length; i++) {
|
|
671
|
+
const ch = line[i];
|
|
672
|
+
if (inQuotes) {
|
|
673
|
+
if (ch === '"') {
|
|
674
|
+
if (i + 1 < line.length && line[i + 1] === '"') {
|
|
675
|
+
current += '"';
|
|
676
|
+
i++;
|
|
677
|
+
} else {
|
|
678
|
+
inQuotes = false;
|
|
679
|
+
}
|
|
680
|
+
} else {
|
|
681
|
+
current += ch;
|
|
682
|
+
}
|
|
683
|
+
} else {
|
|
684
|
+
if (ch === '"') {
|
|
685
|
+
inQuotes = true;
|
|
686
|
+
} else if (ch === ",") {
|
|
687
|
+
result.push(current);
|
|
688
|
+
current = "";
|
|
689
|
+
} else {
|
|
690
|
+
current += ch;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
result.push(current);
|
|
695
|
+
return result;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// ---- Offer Letter Generation ----
|
|
699
|
+
|
|
700
|
+
export interface OfferDetails {
|
|
701
|
+
salary: number;
|
|
702
|
+
start_date: string;
|
|
703
|
+
position_title?: string;
|
|
704
|
+
department?: string;
|
|
705
|
+
benefits?: string;
|
|
706
|
+
equity?: string;
|
|
707
|
+
signing_bonus?: number;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
export function generateOffer(applicantId: string, details: OfferDetails): string {
|
|
711
|
+
const applicant = getApplicant(applicantId);
|
|
712
|
+
if (!applicant) throw new Error(`Applicant '${applicantId}' not found`);
|
|
713
|
+
|
|
714
|
+
const job = getJob(applicant.job_id);
|
|
715
|
+
if (!job) throw new Error(`Job '${applicant.job_id}' not found`);
|
|
716
|
+
|
|
717
|
+
const title = details.position_title || job.title;
|
|
718
|
+
const dept = details.department || job.department || "the team";
|
|
719
|
+
const salary = details.salary.toLocaleString("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0 });
|
|
720
|
+
|
|
721
|
+
let letter = `# Offer Letter
|
|
722
|
+
|
|
723
|
+
**Date:** ${new Date().toISOString().split("T")[0]}
|
|
724
|
+
|
|
725
|
+
Dear **${applicant.name}**,
|
|
726
|
+
|
|
727
|
+
We are pleased to extend an offer of employment for the position of **${title}** in **${dept}**.
|
|
728
|
+
|
|
729
|
+
## Terms of Employment
|
|
730
|
+
|
|
731
|
+
| Detail | Value |
|
|
732
|
+
|--------|-------|
|
|
733
|
+
| **Position** | ${title} |
|
|
734
|
+
| **Department** | ${dept} |
|
|
735
|
+
| **Annual Salary** | ${salary} |
|
|
736
|
+
| **Start Date** | ${details.start_date} |
|
|
737
|
+
| **Employment Type** | ${job.type} |`;
|
|
738
|
+
|
|
739
|
+
if (details.signing_bonus) {
|
|
740
|
+
const bonus = details.signing_bonus.toLocaleString("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0 });
|
|
741
|
+
letter += `\n| **Signing Bonus** | ${bonus} |`;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (details.equity) {
|
|
745
|
+
letter += `\n| **Equity** | ${details.equity} |`;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
if (details.benefits) {
|
|
749
|
+
letter += `\n\n## Benefits\n\n${details.benefits}`;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
letter += `
|
|
753
|
+
|
|
754
|
+
## Next Steps
|
|
755
|
+
|
|
756
|
+
Please review this offer carefully. To accept, please sign and return this letter by **${getResponseDeadline(details.start_date)}**.
|
|
757
|
+
|
|
758
|
+
We are excited to have you join ${dept} and look forward to your contributions.
|
|
759
|
+
|
|
760
|
+
Sincerely,
|
|
761
|
+
**Hiring Team**
|
|
762
|
+
`;
|
|
763
|
+
|
|
764
|
+
// Store offer in applicant metadata
|
|
765
|
+
const metadata = {
|
|
766
|
+
...applicant.metadata,
|
|
767
|
+
offer: { ...details, generated_at: new Date().toISOString() },
|
|
768
|
+
};
|
|
769
|
+
updateApplicant(applicantId, { metadata, status: "offered" });
|
|
770
|
+
|
|
771
|
+
return letter;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
function getResponseDeadline(startDate: string): string {
|
|
775
|
+
const start = new Date(startDate);
|
|
776
|
+
const deadline = new Date(start.getTime() - 14 * 24 * 60 * 60 * 1000);
|
|
777
|
+
return deadline.toISOString().split("T")[0];
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
// ---- Pipeline Velocity / Hiring Forecast ----
|
|
781
|
+
|
|
782
|
+
export interface HiringForecast {
|
|
783
|
+
job_id: string;
|
|
784
|
+
job_title: string;
|
|
785
|
+
total_applicants: number;
|
|
786
|
+
current_pipeline: PipelineEntry[];
|
|
787
|
+
avg_days_per_stage: Record<string, number>;
|
|
788
|
+
estimated_days_to_fill: number | null;
|
|
789
|
+
conversion_rates: Record<string, number>;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
export function getHiringForecast(jobId: string): HiringForecast {
|
|
793
|
+
const db = getDatabase();
|
|
794
|
+
const job = getJob(jobId);
|
|
795
|
+
if (!job) throw new Error(`Job '${jobId}' not found`);
|
|
796
|
+
|
|
797
|
+
const pipeline = getPipeline(jobId);
|
|
798
|
+
const applicants = listApplicants({ job_id: jobId });
|
|
799
|
+
|
|
800
|
+
// Calculate stage transition times from applicant update timestamps
|
|
801
|
+
const stages = ["applied", "screening", "interviewing", "offered", "hired"];
|
|
802
|
+
const stageDurations: Record<string, number[]> = {};
|
|
803
|
+
|
|
804
|
+
for (const applicant of applicants) {
|
|
805
|
+
// Use created_at and updated_at to estimate stage duration
|
|
806
|
+
if (applicant.status !== "applied" && applicant.status !== "rejected") {
|
|
807
|
+
const created = new Date(applicant.created_at).getTime();
|
|
808
|
+
const updated = new Date(applicant.updated_at).getTime();
|
|
809
|
+
const days = (updated - created) / (1000 * 60 * 60 * 24);
|
|
810
|
+
if (days > 0) {
|
|
811
|
+
const key = `applied->${applicant.status}`;
|
|
812
|
+
if (!stageDurations[key]) stageDurations[key] = [];
|
|
813
|
+
stageDurations[key].push(days);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
const avgDaysPerStage: Record<string, number> = {};
|
|
819
|
+
for (const [key, durations] of Object.entries(stageDurations)) {
|
|
820
|
+
avgDaysPerStage[key] = Math.round((durations.reduce((a, b) => a + b, 0) / durations.length) * 10) / 10;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
// Calculate conversion rates between stages
|
|
824
|
+
const conversionRates: Record<string, number> = {};
|
|
825
|
+
const statusCounts: Record<string, number> = {};
|
|
826
|
+
for (const p of pipeline) {
|
|
827
|
+
statusCounts[p.status] = p.count;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
const total = applicants.length;
|
|
831
|
+
if (total > 0) {
|
|
832
|
+
for (const stage of stages) {
|
|
833
|
+
const atOrPast = applicants.filter((a) => {
|
|
834
|
+
const idx = stages.indexOf(a.status);
|
|
835
|
+
const stageIdx = stages.indexOf(stage);
|
|
836
|
+
return idx >= stageIdx && a.status !== "rejected";
|
|
837
|
+
}).length;
|
|
838
|
+
conversionRates[stage] = Math.round((atOrPast / total) * 100);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// Estimate days to fill: sum of avg days per stage transition for the full pipeline
|
|
843
|
+
let estimatedDays: number | null = null;
|
|
844
|
+
if (Object.keys(avgDaysPerStage).length > 0) {
|
|
845
|
+
// Use the longest observed transition as an estimate
|
|
846
|
+
const values = Object.values(avgDaysPerStage);
|
|
847
|
+
estimatedDays = Math.round(values.reduce((a, b) => Math.max(a, b), 0) * 1.2);
|
|
848
|
+
} else if (applicants.length > 0) {
|
|
849
|
+
// Fallback: estimate based on overall pipeline age
|
|
850
|
+
const oldest = applicants.reduce((oldest, a) => {
|
|
851
|
+
const t = new Date(a.created_at).getTime();
|
|
852
|
+
return t < oldest ? t : oldest;
|
|
853
|
+
}, Date.now());
|
|
854
|
+
const daysSinceFirst = (Date.now() - oldest) / (1000 * 60 * 60 * 24);
|
|
855
|
+
const hiredCount = statusCounts["hired"] || 0;
|
|
856
|
+
if (hiredCount > 0) {
|
|
857
|
+
estimatedDays = Math.round(daysSinceFirst / hiredCount);
|
|
858
|
+
} else {
|
|
859
|
+
estimatedDays = Math.round(daysSinceFirst * 2);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
return {
|
|
864
|
+
job_id: jobId,
|
|
865
|
+
job_title: job.title,
|
|
866
|
+
total_applicants: total,
|
|
867
|
+
current_pipeline: pipeline,
|
|
868
|
+
avg_days_per_stage: avgDaysPerStage,
|
|
869
|
+
estimated_days_to_fill: estimatedDays,
|
|
870
|
+
conversion_rates: conversionRates,
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// ---- Structured Interview Feedback ----
|
|
875
|
+
|
|
876
|
+
export interface StructuredFeedback {
|
|
877
|
+
technical?: number;
|
|
878
|
+
communication?: number;
|
|
879
|
+
culture_fit?: number;
|
|
880
|
+
problem_solving?: number;
|
|
881
|
+
leadership?: number;
|
|
882
|
+
overall?: number;
|
|
883
|
+
notes?: string;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
export function submitStructuredFeedback(
|
|
887
|
+
interviewId: string,
|
|
888
|
+
scores: StructuredFeedback,
|
|
889
|
+
feedbackText?: string
|
|
890
|
+
): Interview | null {
|
|
891
|
+
const interview = getInterview(interviewId);
|
|
892
|
+
if (!interview) return null;
|
|
893
|
+
|
|
894
|
+
// Build feedback JSON with scores and text
|
|
895
|
+
const feedbackData = {
|
|
896
|
+
scores,
|
|
897
|
+
text: feedbackText || interview.feedback || "",
|
|
898
|
+
submitted_at: new Date().toISOString(),
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
// Calculate average score from provided dimensions
|
|
902
|
+
const scoreValues = [
|
|
903
|
+
scores.technical,
|
|
904
|
+
scores.communication,
|
|
905
|
+
scores.culture_fit,
|
|
906
|
+
scores.problem_solving,
|
|
907
|
+
scores.leadership,
|
|
908
|
+
scores.overall,
|
|
909
|
+
].filter((v): v is number => v !== undefined);
|
|
910
|
+
|
|
911
|
+
const avgRating = scoreValues.length > 0
|
|
912
|
+
? Math.round((scoreValues.reduce((a, b) => a + b, 0) / scoreValues.length) * 10) / 10
|
|
913
|
+
: undefined;
|
|
914
|
+
|
|
915
|
+
return updateInterview(interviewId, {
|
|
916
|
+
feedback: JSON.stringify(feedbackData),
|
|
917
|
+
rating: avgRating,
|
|
918
|
+
status: "completed",
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// ---- Bulk Rejection ----
|
|
923
|
+
|
|
924
|
+
export interface BulkRejectResult {
|
|
925
|
+
rejected: number;
|
|
926
|
+
applicant_ids: string[];
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
export function bulkReject(
|
|
930
|
+
jobId: string,
|
|
931
|
+
status: Applicant["status"],
|
|
932
|
+
reason?: string
|
|
933
|
+
): BulkRejectResult {
|
|
934
|
+
const applicants = listApplicants({ job_id: jobId, status });
|
|
935
|
+
const rejected: string[] = [];
|
|
936
|
+
|
|
937
|
+
for (const applicant of applicants) {
|
|
938
|
+
const result = rejectApplicant(applicant.id, reason);
|
|
939
|
+
if (result) rejected.push(applicant.id);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
return { rejected: rejected.length, applicant_ids: rejected };
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// ---- Referral Stats ----
|
|
946
|
+
|
|
947
|
+
export interface ReferralStats {
|
|
948
|
+
source: string;
|
|
949
|
+
total: number;
|
|
950
|
+
hired: number;
|
|
951
|
+
rejected: number;
|
|
952
|
+
in_progress: number;
|
|
953
|
+
conversion_rate: number;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
export function getReferralStats(): ReferralStats[] {
|
|
957
|
+
const db = getDatabase();
|
|
958
|
+
|
|
959
|
+
const rows = db.prepare(`
|
|
960
|
+
SELECT
|
|
961
|
+
COALESCE(source, 'unknown') as source,
|
|
962
|
+
COUNT(*) as total,
|
|
963
|
+
SUM(CASE WHEN status = 'hired' THEN 1 ELSE 0 END) as hired,
|
|
964
|
+
SUM(CASE WHEN status = 'rejected' THEN 1 ELSE 0 END) as rejected,
|
|
965
|
+
SUM(CASE WHEN status NOT IN ('hired', 'rejected') THEN 1 ELSE 0 END) as in_progress
|
|
966
|
+
FROM applicants
|
|
967
|
+
GROUP BY COALESCE(source, 'unknown')
|
|
968
|
+
ORDER BY total DESC
|
|
969
|
+
`).all() as Array<{
|
|
970
|
+
source: string;
|
|
971
|
+
total: number;
|
|
972
|
+
hired: number;
|
|
973
|
+
rejected: number;
|
|
974
|
+
in_progress: number;
|
|
975
|
+
}>;
|
|
976
|
+
|
|
977
|
+
return rows.map((r) => ({
|
|
978
|
+
...r,
|
|
979
|
+
conversion_rate: r.total > 0 ? Math.round((r.hired / r.total) * 100 * 10) / 10 : 0,
|
|
980
|
+
}));
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
// ---- Job Templates ----
|
|
984
|
+
|
|
985
|
+
export interface JobTemplate {
|
|
986
|
+
id: string;
|
|
987
|
+
name: string;
|
|
988
|
+
title: string;
|
|
989
|
+
department: string | null;
|
|
990
|
+
location: string | null;
|
|
991
|
+
type: "full-time" | "part-time" | "contract";
|
|
992
|
+
description: string | null;
|
|
993
|
+
requirements: string[];
|
|
994
|
+
salary_range: string | null;
|
|
995
|
+
created_at: string;
|
|
996
|
+
updated_at: string;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
interface JobTemplateRow {
|
|
1000
|
+
id: string;
|
|
1001
|
+
name: string;
|
|
1002
|
+
title: string;
|
|
1003
|
+
department: string | null;
|
|
1004
|
+
location: string | null;
|
|
1005
|
+
type: string;
|
|
1006
|
+
description: string | null;
|
|
1007
|
+
requirements: string;
|
|
1008
|
+
salary_range: string | null;
|
|
1009
|
+
created_at: string;
|
|
1010
|
+
updated_at: string;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
function rowToJobTemplate(row: JobTemplateRow): JobTemplate {
|
|
1014
|
+
return {
|
|
1015
|
+
...row,
|
|
1016
|
+
type: row.type as JobTemplate["type"],
|
|
1017
|
+
requirements: JSON.parse(row.requirements || "[]"),
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
export function saveJobAsTemplate(jobId: string, templateName: string): JobTemplate {
|
|
1022
|
+
const db = getDatabase();
|
|
1023
|
+
const job = getJob(jobId);
|
|
1024
|
+
if (!job) throw new Error(`Job '${jobId}' not found`);
|
|
1025
|
+
|
|
1026
|
+
const id = crypto.randomUUID();
|
|
1027
|
+
const requirements = JSON.stringify(job.requirements);
|
|
1028
|
+
|
|
1029
|
+
db.prepare(
|
|
1030
|
+
`INSERT INTO job_templates (id, name, title, department, location, type, description, requirements, salary_range)
|
|
1031
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
1032
|
+
).run(
|
|
1033
|
+
id,
|
|
1034
|
+
templateName,
|
|
1035
|
+
job.title,
|
|
1036
|
+
job.department,
|
|
1037
|
+
job.location,
|
|
1038
|
+
job.type,
|
|
1039
|
+
job.description,
|
|
1040
|
+
requirements,
|
|
1041
|
+
job.salary_range
|
|
1042
|
+
);
|
|
1043
|
+
|
|
1044
|
+
return getJobTemplate(id)!;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
export function getJobTemplate(id: string): JobTemplate | null {
|
|
1048
|
+
const db = getDatabase();
|
|
1049
|
+
const row = db.prepare("SELECT * FROM job_templates WHERE id = ?").get(id) as JobTemplateRow | null;
|
|
1050
|
+
return row ? rowToJobTemplate(row) : null;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
export function getJobTemplateByName(name: string): JobTemplate | null {
|
|
1054
|
+
const db = getDatabase();
|
|
1055
|
+
const row = db.prepare("SELECT * FROM job_templates WHERE name = ?").get(name) as JobTemplateRow | null;
|
|
1056
|
+
return row ? rowToJobTemplate(row) : null;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
export function listJobTemplates(): JobTemplate[] {
|
|
1060
|
+
const db = getDatabase();
|
|
1061
|
+
const rows = db.prepare("SELECT * FROM job_templates ORDER BY name ASC").all() as JobTemplateRow[];
|
|
1062
|
+
return rows.map(rowToJobTemplate);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
export function createJobFromTemplate(templateName: string, overrides?: Partial<CreateJobInput>): Job {
|
|
1066
|
+
const template = getJobTemplateByName(templateName);
|
|
1067
|
+
if (!template) throw new Error(`Template '${templateName}' not found`);
|
|
1068
|
+
|
|
1069
|
+
return createJob({
|
|
1070
|
+
title: overrides?.title || template.title,
|
|
1071
|
+
department: overrides?.department || template.department || undefined,
|
|
1072
|
+
location: overrides?.location || template.location || undefined,
|
|
1073
|
+
type: overrides?.type || template.type,
|
|
1074
|
+
description: overrides?.description || template.description || undefined,
|
|
1075
|
+
requirements: overrides?.requirements || template.requirements,
|
|
1076
|
+
salary_range: overrides?.salary_range || template.salary_range || undefined,
|
|
1077
|
+
posted_at: overrides?.posted_at,
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
export function deleteJobTemplate(id: string): boolean {
|
|
1082
|
+
const db = getDatabase();
|
|
1083
|
+
const result = db.prepare("DELETE FROM job_templates WHERE id = ?").run(id);
|
|
1084
|
+
return result.changes > 0;
|
|
1085
|
+
}
|
|
@@ -65,4 +65,25 @@ export const MIGRATIONS: MigrationEntry[] = [
|
|
|
65
65
|
CREATE INDEX IF NOT EXISTS idx_interviews_status ON interviews(status);
|
|
66
66
|
`,
|
|
67
67
|
},
|
|
68
|
+
{
|
|
69
|
+
id: 2,
|
|
70
|
+
name: "add_job_templates",
|
|
71
|
+
sql: `
|
|
72
|
+
CREATE TABLE IF NOT EXISTS job_templates (
|
|
73
|
+
id TEXT PRIMARY KEY,
|
|
74
|
+
name TEXT NOT NULL UNIQUE,
|
|
75
|
+
title TEXT NOT NULL,
|
|
76
|
+
department TEXT,
|
|
77
|
+
location TEXT,
|
|
78
|
+
type TEXT NOT NULL DEFAULT 'full-time' CHECK (type IN ('full-time', 'part-time', 'contract')),
|
|
79
|
+
description TEXT,
|
|
80
|
+
requirements TEXT NOT NULL DEFAULT '[]',
|
|
81
|
+
salary_range TEXT,
|
|
82
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
83
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
CREATE INDEX IF NOT EXISTS idx_job_templates_name ON job_templates(name);
|
|
87
|
+
`,
|
|
88
|
+
},
|
|
68
89
|
];
|
|
@@ -48,4 +48,33 @@ export {
|
|
|
48
48
|
type ListInterviewsOptions,
|
|
49
49
|
} from "./db/hiring.js";
|
|
50
50
|
|
|
51
|
+
export {
|
|
52
|
+
bulkImportApplicants,
|
|
53
|
+
generateOffer,
|
|
54
|
+
getHiringForecast,
|
|
55
|
+
submitStructuredFeedback,
|
|
56
|
+
bulkReject,
|
|
57
|
+
getReferralStats,
|
|
58
|
+
saveJobAsTemplate,
|
|
59
|
+
getJobTemplate,
|
|
60
|
+
getJobTemplateByName,
|
|
61
|
+
listJobTemplates,
|
|
62
|
+
createJobFromTemplate,
|
|
63
|
+
deleteJobTemplate,
|
|
64
|
+
type BulkImportResult,
|
|
65
|
+
type OfferDetails,
|
|
66
|
+
type HiringForecast,
|
|
67
|
+
type StructuredFeedback,
|
|
68
|
+
type BulkRejectResult,
|
|
69
|
+
type ReferralStats,
|
|
70
|
+
type JobTemplate,
|
|
71
|
+
} from "./db/hiring.js";
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
scoreApplicant,
|
|
75
|
+
rankApplicants,
|
|
76
|
+
type ScoreResult,
|
|
77
|
+
type RankEntry,
|
|
78
|
+
} from "./lib/scoring.js";
|
|
79
|
+
|
|
51
80
|
export { getDatabase, closeDatabase } from "./db/database.js";
|