MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / updateProfile

Function updateProfile

apps/api/src/controllers/profile.controller.ts:12–51  ·  view source on GitHub ↗
(
  request: FastifyRequest<{
    Body: DeprecatedUpdateProfilePayload;
  }>,
  reply: FastifyReply,
)

Source from the content-addressed store, hash-verified

10} from '@openpanel/validation';
11
12export async function updateProfile(
13 request: FastifyRequest<{
14 Body: DeprecatedUpdateProfilePayload;
15 }>,
16 reply: FastifyReply,
17) {
18 const payload = request.body;
19 const projectId = request.client!.projectId;
20 if (!projectId) {
21 return reply.status(400).send('No projectId');
22 }
23 const ip = request.clientIp;
24 const ua = request.headers['user-agent'];
25 const uaInfo = parseUserAgent(ua, payload.properties);
26 const geo = await getGeoLocation(ip);
27
28 await upsertProfile({
29 ...payload,
30 id: payload.profileId,
31 isExternal: true,
32 projectId,
33 properties: {
34 ...(payload.properties ?? {}),
35 country: geo.country,
36 city: geo.city,
37 region: geo.region,
38 longitude: geo.longitude,
39 latitude: geo.latitude,
40 os: uaInfo.os,
41 os_version: uaInfo.osVersion,
42 browser: uaInfo.browser,
43 browser_version: uaInfo.browserVersion,
44 device: uaInfo.device,
45 brand: uaInfo.brand,
46 model: uaInfo.model,
47 },
48 });
49
50 reply.status(202).send(payload.profileId);
51}
52
53export async function incrementProfileProperty(
54 request: FastifyRequest<{

Callers

nothing calls this directly

Calls 4

parseUserAgentFunction · 0.90
getGeoLocationFunction · 0.90
upsertProfileFunction · 0.90
sendMethod · 0.45

Tested by

no test coverage detected