| 50 | const SOCIAL_LINK_KEYS = ["phoneNumber", "github", "instagram", "linkedin", "twitter", "peerlist", "behance", "dribbble"] as const; |
| 51 | |
| 52 | const buildApplicationUpdatePayload = (body: applicationUpdatePayload): Record<string, string | number | undefined> => { |
| 53 | const dataToUpdate: Record<string, string | number | undefined> = {}; |
| 54 | |
| 55 | Object.entries(FLAT_FIELD_MAP).forEach(([key, path]) => { |
| 56 | const value = body[key as keyof typeof FLAT_FIELD_MAP]; |
| 57 | if (value != null) { |
| 58 | dataToUpdate[path] = value; |
| 59 | } |
| 60 | }); |
| 61 | |
| 62 | if (body.professional && typeof body.professional === "object") { |
| 63 | PROFESSIONAL_KEYS.forEach((key) => { |
| 64 | const value = body.professional![key]; |
| 65 | if (value != null) { |
| 66 | dataToUpdate[`professional.${key}`] = value; |
| 67 | } |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | if (body.socialLink && typeof body.socialLink === "object") { |
| 72 | SOCIAL_LINK_KEYS.forEach((key) => { |
| 73 | const value = body.socialLink![key]; |
| 74 | if (value != null) { |
| 75 | dataToUpdate[`socialLink.${key}`] = value; |
| 76 | } |
| 77 | }); |
| 78 | } |
| 79 | |
| 80 | return dataToUpdate; |
| 81 | }; |
| 82 | |
| 83 | module.exports = { getUserApplicationObject, buildApplicationUpdatePayload } |