Files
edr-platform/apps/edr-freight-api/src/modules/companies/entities/company.entity.ts
Nathnael d67297a601 feat(freight): record when a company is approved
Ticket #420 — add approved_at to companies (migration), stamped at
both promotion sites (first-profile auto-approve and manual staff
status change). Surfaced as Submitted on/Approved on in the backoffice
customer list and detail views.
2026-07-31 11:43:36 +00:00

212 lines
5.2 KiB
TypeScript

import { BaseEntity } from "@edr/api-common";
import { Column, Entity, Index, OneToMany } from "typeorm";
import { ExternalProfile } from "./external-profile.entity";
import { CompanyProfile } from "./company-profile.entity";
export enum CompanyType {
Customer = "customer",
FreightForwarder = "freight_forwarder",
DJFreightForwarder = "dj_freight_forwarder",
Transporter = "transporter",
}
/**
* Sector of the company — orthogonal to {@link CompanyType} (the trade role).
* Government bookings are billed to a single seeded `GOVERNMENT` company instead
* of carrying a null company + free-text institution.
*/
export enum CompanyKind {
Commercial = "commercial",
Government = "government",
}
export enum CompanyStatus {
Active = "active",
Pending = "pending",
Suspended = "suspended",
Blacklisted = "blacklisted",
}
export enum CompanyNationality {
Ethiopian = "ethiopian",
Foreign = "foreign",
}
@Entity({ schema: "freight", name: "companies" })
@Index(["tin"])
@Index(["type"])
@Index(["kind"])
export class Company extends BaseEntity {
@Column({ name: "name", type: "varchar", length: 200 })
name!: string;
@Column({ name: "type", type: "varchar", length: 32, enum: CompanyType })
type!: CompanyType;
/** Commercial customer vs. the seeded government entity. */
@Column({
name: "kind",
type: "varchar",
length: 20,
default: CompanyKind.Commercial,
enum: CompanyKind,
})
kind!: CompanyKind;
@Column({
name: "status",
type: "varchar",
length: 32,
default: CompanyStatus.Pending,
})
status!: CompanyStatus;
/** Set when the company is first promoted Pending → Active. Null for companies approved before this column existed. */
@Column({ name: "approved_at", type: "timestamptz", nullable: true })
approvedAt?: Date | null;
@Column({ name: "tin", type: "varchar", length: 10, unique: true })
tin!: string;
@Column({ name: "vat_number", type: "varchar", length: 50, nullable: true })
vatNumber?: string | null;
@Column({ name: "fan_number", type: "varchar", length: 16, nullable: true })
fanNumber?: string | null;
@Column({ name: "country", type: "varchar", length: 32, default: "Ethiopia" })
country!: string;
/** Whether the company is Ethiopian or Foreign — drives the required onboarding documents. */
@Column({
name: "nationality",
type: "varchar",
length: 32,
nullable: true,
enum: CompanyNationality,
})
nationality?: CompanyNationality | null;
@Column({ name: "address", type: "text", nullable: true })
address?: string | null;
@Column({ name: "phone", type: "varchar", length: 20, nullable: true })
phone?: string | null;
@Column({ name: "email", type: "varchar", length: 150, nullable: true })
email?: string | null;
@Column({
name: "contact_person_name",
type: "varchar",
length: 100,
nullable: true,
})
contactPersonName?: string | null;
@Column({
name: "contact_person_phone",
type: "varchar",
length: 20,
nullable: true,
})
contactPersonPhone?: string | null;
@Column({
name: "general_manager_name",
type: "varchar",
length: 100,
nullable: true,
})
generalManagerName?: string | null;
@Column({
name: "general_manager_email",
type: "varchar",
length: 150,
nullable: true,
})
generalManagerEmail?: string | null;
@Column({
name: "general_manager_phone",
type: "varchar",
length: 20,
nullable: true,
})
generalManagerPhone?: string | null;
@Column({ name: "website", type: "varchar", length: 200, nullable: true })
website?: string | null;
@Column({ name: "attributes", type: "jsonb", nullable: true })
attributes?: Record<string, any> | null;
@Column({
name: "licence_number",
type: "varchar",
length: 100,
nullable: true,
})
licenceNumber?: string | null;
@Column({ name: "status_description", type: "text", nullable: true })
statusDescription?: string | null;
@Column({
name: "date_registered",
type: "varchar",
length: 50,
nullable: true,
})
dateRegistered?: string | null;
@Column({
name: "renewed_from",
type: "varchar",
length: 50,
nullable: true,
})
renewedFrom?: string | null;
@Column({
name: "renewal_date",
type: "varchar",
length: 50,
nullable: true,
})
renewalDate?: string | null;
@Column({
name: "renewed_to",
type: "varchar",
length: 50,
nullable: true,
})
renewedTo?: string | null;
@Column({ name: "region", type: "varchar", length: 100, nullable: true })
region?: string | null;
@Column({ name: "zone", type: "varchar", length: 100, nullable: true })
zone?: string | null;
@Column({ name: "woreda", type: "varchar", length: 100, nullable: true })
woreda?: string | null;
@Column({ name: "kebele", type: "varchar", length: 100, nullable: true })
kebele?: string | null;
@Column({ name: "house_no", type: "varchar", length: 100, nullable: true })
houseNo?: string | null;
@Column({ name: "etrade_phone", type: "varchar", length: 20, nullable: true })
etradePhone?: string | null;
@OneToMany(() => ExternalProfile, (profile) => profile.company)
profiles?: ExternalProfile[];
@OneToMany(() => CompanyProfile, (profile) => profile.company)
companyProfiles?: CompanyProfile[];
}