Skip to content

Commit

Permalink
gives sb user supporter for change their names
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Aug 19, 2023
1 parent dd78b0a commit 285a45a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
13 changes: 13 additions & 0 deletions src/server/backend/$base/server/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ export abstract class UserProvider<Id> extends idTransformable {
]: UserProvider.ComposableProperties<Id>[K];
}
>
getFullWithSettings<
Excludes extends Partial<
Record<keyof UserProvider.ComposableProperties<Id>, boolean>
>,
_Scope extends Scope = Scope.Public,
>(query: {
handle: string
excludes?: Excludes
includeHidden?: boolean
scope: _Scope
}) {
return this.getFull(query)
}

abstract changeSettings(
user: { id: Id },
Expand Down
19 changes: 13 additions & 6 deletions src/server/backend/[email protected]/server/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { toFullUser } from '~/server/backend/bancho.py/transforms'
import { createUserQuery } from '~/server/backend/bancho.py/db-query'

import type { Scope, UserEssential, UserOldName } from '~/def/user'
import { UserStatus } from '~/def/user'
import { UserPrivilege, UserStatus } from '~/def/user'

import { type UserProvider as Base } from '$base/server'

Expand All @@ -18,10 +18,6 @@ const logger = Logger.child({ label: 'user' })
export class UserProvider extends BanchoPyUser implements Base<Id> {
sbDb = getPrismaClient()

constructor() {
super()
}

async changeUserpage(
user: UserEssential<number>,
input: { profile: ArticleProvider.JSONContent }
Expand Down Expand Up @@ -92,7 +88,7 @@ export class UserProvider extends BanchoPyUser implements Base<Id> {
privilege: includeHidden ? BanchoPyPrivilege.Any : undefined,
}))

const fullUser = await toFullUser(user, this.config)
const fullUser = toFullUser(user, this.config)
const profile = await this.sbDb.userpage.findFirst({
where: {
userId: user.id,
Expand Down Expand Up @@ -130,4 +126,15 @@ export class UserProvider extends BanchoPyUser implements Base<Id> {

return returnValue
}

async getFullWithSettings<
Excludes extends Partial<Record<keyof Base.ComposableProperties<Id>, boolean>>,
_Scope extends Scope = Scope.Public,
>(query: { handle: string; excludes?: Excludes; includeHidden?: boolean; scope: _Scope }) {
const fullUser = await this.getFull(query)
if (!fullUser.roles.includes(UserPrivilege.Supporter)) {
fullUser.roles.push(UserPrivilege.Supporter)
}
return fullUser
}
}
2 changes: 1 addition & 1 deletion src/server/trpc/routers/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const relations = new UserRelationProvider()
const session = new SessionProvider()
export const router = _router({
settings: pUser.query(async ({ ctx }) => {
return await users.getFull({
return await users.getFullWithSettings({
handle: UserProvider.idToString(ctx.user.id),
includeHidden: true,
excludes: { statistics: true, relationships: true, secrets: false },
Expand Down
16 changes: 1 addition & 15 deletions src/server/trpc/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const router = _router({
.query(async ({ input: { handle }, ctx }) => {
const user = await userProvider.getFull({
handle,
excludes: { relationships: true, secrets: true },
excludes: { relationships: true, secrets: true, email: true },
includeHidden: true,
scope: Scope.Public,
})
Expand All @@ -54,20 +54,6 @@ export const router = _router({
}
return mapId(user, UserProvider.idToString)
}),
full: p
.input(
object({
handle: zodHandle,
})
)
.query(async ({ input: { handle } }) => {
const user = await userProvider.getFull({
handle,
excludes: { email: true },
scope: Scope.Public,
})
return mapId(user, UserProvider.idToString)
}),
best: p
.input(
object({
Expand Down

0 comments on commit 285a45a

Please sign in to comment.