1- import type { FastifyInstance } from 'fastify'
21import { getProfileUrl } from '@devcard/shared'
2+
33import { getErrorMessage } from '../utils/error.util.js'
44
5+ import type { FastifyInstance } from 'fastify'
6+
57export async function getOwnProfile ( app : FastifyInstance , userId : string ) {
68 const user = await app . prisma . user . findUnique ( {
79 where : { id : userId } ,
@@ -11,9 +13,9 @@ export async function getOwnProfile(app: FastifyInstance, userId: string) {
1113 } ,
1214 } )
1315
14- if ( ! user ) return null
16+ if ( ! user ) { return null }
1517
16- const { provider, providerId, ...profileData } = user as any
18+ const { provider : _provider , providerId : _providerId , ...profileData } = user as any
1719 return { ...profileData , defaultCardId : user . cards [ 0 ] ?. id || null }
1820}
1921
@@ -23,7 +25,7 @@ export async function updateProfile(app: FastifyInstance, userId: string, data:
2325 const existing = await app . prisma . user . findFirst ( {
2426 where : { username : data . username , NOT : { id : userId } } ,
2527 } )
26- if ( existing ) throw Object . assign ( new Error ( 'Username taken' ) , { code : 'P2002' } )
28+ if ( existing ) { throw Object . assign ( new Error ( 'Username taken' ) , { code : 'P2002' } ) }
2729 }
2830
2931 const currentUser = await app . prisma . user . findUnique ( { where : { id : userId } , select : { username : true } } )
@@ -41,7 +43,7 @@ export async function updateProfile(app: FastifyInstance, userId: string, data:
4143
4244 return response
4345 } catch ( err : any ) {
44- if ( err ?. code === 'P2002' ) throw err
46+ if ( err ?. code === 'P2002' ) { throw err }
4547 app . log . error ( { err } , 'DB error in updateProfile' )
4648 throw err
4749 }
@@ -55,14 +57,14 @@ export async function createPlatformLink(app: FastifyInstance, userId: string, l
5557
5658export async function updatePlatformLink ( app : FastifyInstance , userId : string , id : string , linkData : any ) {
5759 const existing = await app . prisma . platformLink . findFirst ( { where : { id, userId } } )
58- if ( ! existing ) return null
60+ if ( ! existing ) { return null }
5961 const url = linkData . url || getProfileUrl ( linkData . platform , linkData . username )
6062 return app . prisma . platformLink . update ( { where : { id } , data : { platform : linkData . platform , username : linkData . username , url } } )
6163}
6264
6365export async function deletePlatformLink ( app : FastifyInstance , userId : string , id : string ) {
6466 const existing = await app . prisma . platformLink . findFirst ( { where : { id, userId } } )
65- if ( ! existing ) return false
67+ if ( ! existing ) { return false }
6668 await app . prisma . platformLink . delete ( { where : { id } } )
6769 return true
6870}
0 commit comments