mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 03:02:03 +00:00
45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import type { TeamMemberListItem } from "@/domain/team-members/types/team-member";
|
|
|
|
function readString(record: Record<string, unknown>, ...keys: string[]): string {
|
|
for (const key of keys) {
|
|
const value = record[key];
|
|
if (typeof value === "string") return value;
|
|
if (typeof value === "number") return String(value);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
function readBoolean(record: Record<string, unknown>, ...keys: string[]): boolean {
|
|
for (const key of keys) {
|
|
const value = record[key];
|
|
if (typeof value === "boolean") return value;
|
|
if (typeof value === "string") return value.toLowerCase() === "true";
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export function mapTeamMemberListItem(raw: unknown): TeamMemberListItem {
|
|
const record = (typeof raw === "object" && raw !== null ? raw : {}) as Record<string, unknown>;
|
|
const id = record.id ?? record.Id;
|
|
const status =
|
|
readString(record, "status", "Status").toLowerCase() === "inactive" ||
|
|
readBoolean(record, "isDeleted", "IsDeleted")
|
|
? "Inactive"
|
|
: "Active";
|
|
|
|
return {
|
|
id: typeof id === "string" || typeof id === "number" ? id : "",
|
|
name: readString(record, "name", "Name"),
|
|
role: readString(record, "role", "Role", "roleName", "RoleName"),
|
|
serviceArea: readString(record, "serviceArea", "ServiceArea", "locations", "Locations"),
|
|
phone: readString(record, "phone", "Phone"),
|
|
email: readString(record, "email", "Email"),
|
|
color: readString(record, "color", "Color"),
|
|
status,
|
|
isAccountOwner: readBoolean(record, "isAccountOwner", "IsAccountOwner"),
|
|
};
|
|
}
|
|
|
|
export function mapTeamMemberListItems(rawItems: unknown[]): TeamMemberListItem[] {
|
|
return rawItems.map(mapTeamMemberListItem);
|
|
}
|