Skip to content

Commit

Permalink
Merge branch 'master' into feat-reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 authored Dec 15, 2024
2 parents 2e2ac28 + 2172c82 commit 6932347
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/types/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { parse as parseTimelineImage } from '@app/lib/timeline/image';
import { parse as parseTimelineMemo } from '@app/lib/timeline/memo';
import type * as res from '@app/lib/types/res.ts';
import {
findNetworkService,
findSubjectPlatform,
findSubjectRelationType,
findSubjectStaffPosition,
Expand Down Expand Up @@ -105,6 +106,7 @@ export function toUser(user: orm.IUser, fields: orm.IUserFields): res.IUser {
site: fields.site,
location: fields.location,
bio: fields.bio,
networkServices: [],
// homepage: toUserHomepage(fields.homepage),
};
}
Expand All @@ -120,6 +122,26 @@ export function toSlimUser(user: orm.IUser): res.ISlimUser {
};
}

export function toUserNetworkService(service: orm.IUserNetworkServices): res.IUserNetworkService {
const svc = findNetworkService(service.serviceID);
if (!svc) {
return {
title: '',
name: '',
url: '',
color: '',
account: service.account,
};
}
return {
title: svc.title,
name: svc.name,
url: svc.url || '',
color: svc.bg_color,
account: service.account,
};
}

export function toFriend(user: orm.IUser, friend: orm.IFriend): res.IFriend {
return {
user: toSlimUser(user),
Expand Down
13 changes: 13 additions & 0 deletions lib/types/res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ export const Avatar = t.Object(
{ $id: 'Avatar', title: 'Avatar' },
);

export type IUserNetworkService = Static<typeof UserNetworkService>;
export const UserNetworkService = t.Object(
{
name: t.String(),
title: t.String(),
url: t.String(),
color: t.String(),
account: t.String(),
},
{ $id: 'UserNetworkService', title: 'UserNetworkService' },
);

export type IUserHomepage = Static<typeof UserHomepage>;
export const UserHomepage = t.Object(
{
Expand Down Expand Up @@ -104,6 +116,7 @@ export const User = t.Object(
site: t.String(),
location: t.String(),
bio: t.String(),
networkServices: t.Array(UserNetworkService),
// wait for permission
// homepage: t.Ref(UserHomepage),
},
Expand Down
43 changes: 43 additions & 0 deletions routes/__snapshots__/index.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions routes/private/routes/__snapshots__/user.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions routes/private/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ export async function setup(app: App) {
throw new NotFoundError(`user ${username}`);
}
const user = convert.toUser(data.chii_members, data.chii_memberfields);
const svcs = await db
.select()
.from(schema.chiiUserNetworkServices)
.where(op.eq(schema.chiiUserNetworkServices.uid, user.id))
.execute();
for (const svc of svcs) {
user.networkServices.push(convert.toUserNetworkService(svc));
}
return user;
},
);
Expand Down

0 comments on commit 6932347

Please sign in to comment.