added profile description editing, fixed light theme and viewer caching
This commit is contained in:
parent
58a211663a
commit
c8f68b7486
10 changed files with 187 additions and 18 deletions
|
|
@ -6,6 +6,7 @@ export async function toUserSchema(model: User): Promise<UserSchema> {
|
|||
id: model.id,
|
||||
username: model.username,
|
||||
createdAt: model.createdAt.toISOString(),
|
||||
updatedAt: model.updatedAt.toISOString()
|
||||
updatedAt: model.updatedAt.toISOString(),
|
||||
description: model.description
|
||||
};
|
||||
}
|
||||
|
|
|
|||
36
app/server/graphql/resolvers/userUpdateResolver.ts
Normal file
36
app/server/graphql/resolvers/userUpdateResolver.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { ensureIdentity } from '@app/server/helpers';
|
||||
import { IdentityContext } from '@app/server/identity';
|
||||
import { prisma, uuid } from '@app/server/prisma/client';
|
||||
import { MutationUserUpdateArgs, User } from '@generated/types';
|
||||
import { toUserSchema } from './mappers/userMapper';
|
||||
import { call } from '@app/common';
|
||||
|
||||
export async function UserUpdateResolver(
|
||||
_: any,
|
||||
{ input }: MutationUserUpdateArgs,
|
||||
{ identity }: IdentityContext
|
||||
): Promise<User> {
|
||||
ensureIdentity(identity);
|
||||
|
||||
if (input.id != identity.id) throw new Error('Operation is not permitted.'); //todo: add admin access
|
||||
|
||||
if (input.description != null && input.description.length > 700)
|
||||
throw new Error('Description is too long.');
|
||||
|
||||
const description = call((): string | null | undefined => {
|
||||
if (input.description != null && input.description.length !== 0) return input.description;
|
||||
if (input.description != null && input.description.length === 0) return null;
|
||||
return undefined;
|
||||
});
|
||||
|
||||
const updated = await prisma.user.update({
|
||||
where: {
|
||||
id: input.id
|
||||
},
|
||||
data: {
|
||||
description
|
||||
}
|
||||
});
|
||||
|
||||
return toUserSchema(updated);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue