Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 45x 45x 3x 3x 1x 4x 45x | // Onboarding shared utilities
import type { ProfileFields } from "./schemas";
// Flatten a raw DB pro object into the onboarding response shape.
// profileFields may be a JSON string (as returned by D1) or already an object.
export function flattenProForOnboarding(pro: Record<string, unknown>) {
let profileFields: ProfileFields = {};
if (pro.profileFields) {
/* v8 ignore start -- V8 artifact: profileFields always string from D1 in tests */
if (typeof pro.profileFields === "string") {
/* v8 ignore stop */
try {
profileFields = JSON.parse(pro.profileFields) as ProfileFields;
} catch {
profileFields = {};
}
} else {
profileFields = pro.profileFields as ProfileFields;
}
}
return {
businessName: pro.businessName,
slug: pro.slug,
cityId: pro.cityId,
businessTypeId: pro.businessTypeId,
businessTypesSecondary: pro.businessTypesSecondary,
customerSegmentId: pro.customerSegmentId,
customerSegmentsSecondary: pro.customerSegmentsSecondary,
projectScaleIds: pro.projectScaleIds,
serviceCategoryIds: pro.serviceCategoryIds,
materialTagIds: pro.materialTagIds,
serviceAreaIds: pro.serviceAreaIds,
yearsInBusiness: pro.yearsInBusiness,
languagesSpoken: pro.languagesSpoken,
teamSize: pro.teamSize,
timelineCapabilities: pro.timelineCapabilities,
acceptsRushOrders: pro.acceptsRushOrders,
rushOrderPremium: pro.rushOrderPremium,
brandsWorkWith: pro.brandsWorkWith,
brandsOfficialPartner: pro.brandsOfficialPartner,
tagline: pro.tagline,
about: pro.about,
establishedYear: pro.establishedYear,
instagramHandle: pro.instagramHandle,
facebookUrl: pro.facebookUrl,
youtubeUrl: pro.youtubeUrl,
googleBusinessUrl: pro.googleBusinessUrl,
websiteUrl: pro.websiteUrl,
linkedinUrl: pro.linkedinUrl,
whatsapp: pro.whatsapp,
email: pro.email,
whatsappBusinessNumber: pro.whatsappBusinessNumber,
addressLine1: pro.addressLine1,
addressLine2: pro.addressLine2,
addressCity: pro.addressCity,
addressState: pro.addressState,
addressPincode: pro.addressPincode,
hasOwnWorkshop: pro.hasOwnWorkshop,
workshopLocation: pro.workshopLocation,
installationTeamSize: pro.installationTeamSize,
typicalTimelines: pro.typicalTimelines,
pricingTier: pro.pricingTier,
priceRangeMin: pro.priceRangeMin,
priceRangeMax: pro.priceRangeMax,
logoUrl: pro.logoUrl,
brandColorPrimary: pro.brandColorPrimary,
brandColorSecondary: pro.brandColorSecondary,
// Delivery fields from profileFields
factoryMade: profileFields.factoryMade ?? null,
factoryType: profileFields.factoryType ?? null,
siteExecution: profileFields.siteExecution ?? null,
labourOnly: profileFields.labourOnly ?? null,
fullSiteExecution: profileFields.fullSiteExecution ?? null,
materialApproach: profileFields.materialApproach ?? null,
billingModel: profileFields.billingModel ?? null,
deliveryDaysMin: profileFields.deliveryDaysMin ?? null,
deliveryDaysMax: profileFields.deliveryDaysMax ?? null,
// Business type detail fields (stored in profileFields)
pricingModel: profileFields.pricingModel ?? null,
minProjectValue: profileFields.minProjectValue ?? null,
consultationFee: profileFields.consultationFee ?? null,
warrantyYears: profileFields.warrantyYears ?? null,
hasAfterSalesService: profileFields.hasAfterSalesService ?? null,
hasShowroom: profileFields.hasShowroom ?? null,
provides3DDesign: profileFields.provides3DDesign ?? null,
};
}
|