Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/backend/src/routes/cards.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as cardService from '../services/cardService.js'
import { handleDbError } from '../utils/error.util.js';
import { hashIp } from '../utils/refreshToken';
import { createCardSchema ,updateCardSchema, addPlatformLinkSchema} from '../validations/card.validation';
import { hashIp } from '../utils/refreshToken.js';
import { createCardSchema ,updateCardSchema, addPlatformLinkSchema} from '../validations/card.validation.js';

import type { CardResponse, UpdateCardBody,UpdatedCardResponse } from '../services/cardService';
import type { Card } from '@devcard/shared/src/types.js';
import type { CardResponse, UpdateCardBody, UpdatedCardResponse } from '../services/cardService';
import type { Card } from '@devcard/shared';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing typecheck error

import type { CardVisibility } from '@prisma/client';
import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/routes/follow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPlatform, getProfileUrl, getWebViewUrl } from '@devcard/shared/src/platforms.js';
import { getPlatform, getProfileUrl, getWebViewUrl } from '@devcard/shared';

import { decrypt } from '../utils/encryption.js';
import { getErrorMessage } from '../utils/error.util.js';
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/routes/profiles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Prisma } from '@prisma/client';

import * as profileService from '../services/profileService';
import * as profileService from '../services/profileService.js';
import { updateProfileSchema, createLinkSchema, reorderLinksSchema } from '../utils/validators.js';

import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/routes/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import QRCode from 'qrcode'
import {generateUniqueSlug} from '../utils/slug.js'
import { createTeamScehma,inviteMembers,updateTeam } from '../validations/team.validation.js';

import type {PlatformLink, PublicProfile} from '@devcard/shared/src/types.js'
import type {PlatformLink, PublicProfile} from '@devcard/shared'
import type { FastifyInstance } from 'fastify';

type TeamMember = PublicProfile & {
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/services/cardService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Card, CardVisibility, type Prisma } from '@prisma/client';
import QRCode from 'qrcode';

import { generateUniqueSlug } from '../utils/slug';
import { generateUniqueSlug } from '../utils/slug.js';

import type { CreateCardBody } from '../routes/cards';
import type { FastifyInstance } from 'fastify';
Expand Down
18 changes: 10 additions & 8 deletions apps/backend/src/services/profileService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { FastifyInstance } from 'fastify'
import { getProfileUrl } from '@devcard/shared/src/platforms.js'
import { getProfileUrl } from '@devcard/shared'

import { getErrorMessage } from '../utils/error.util.js'

import type { FastifyInstance } from 'fastify'

export async function getOwnProfile(app: FastifyInstance, userId: string) {

Check warning on line 7 in apps/backend/src/services/profileService.ts

View workflow job for this annotation

GitHub Actions / backend-ci

Missing return type on function
const user = await app.prisma.user.findUnique({
where: { id: userId },
include: {
Expand All @@ -11,19 +13,19 @@
},
})

if (!user) return null
if (!user) {return null}

const { provider, providerId, ...profileData } = user as any
const { provider: _provider, providerId: _providerId, ...profileData } = user as any
return { ...profileData, defaultCardId: user.cards[0]?.id || null }
}

export async function updateProfile(app: FastifyInstance, userId: string, data: any) {

Check warning on line 22 in apps/backend/src/services/profileService.ts

View workflow job for this annotation

GitHub Actions / backend-ci

Missing return type on function
// Fast-path uniqueness check
if (data.username) {
const existing = await app.prisma.user.findFirst({
where: { username: data.username, NOT: { id: userId } },
})
if (existing) throw Object.assign(new Error('Username taken'), { code: 'P2002' })
if (existing) {throw Object.assign(new Error('Username taken'), { code: 'P2002' })}
}

const currentUser = await app.prisma.user.findUnique({ where: { id: userId }, select: { username: true } })
Expand All @@ -41,33 +43,33 @@

return response
} catch (err: any) {
if (err?.code === 'P2002') throw err
if (err?.code === 'P2002') {throw err}
app.log.error({ err }, 'DB error in updateProfile')
throw err
}
}

export async function createPlatformLink(app: FastifyInstance, userId: string, linkData: any) {

Check warning on line 52 in apps/backend/src/services/profileService.ts

View workflow job for this annotation

GitHub Actions / backend-ci

Missing return type on function
const url = linkData.url || getProfileUrl(linkData.platform, linkData.username)
const maxOrder = await app.prisma.platformLink.aggregate({ where: { userId }, _max: { displayOrder: true } })
return app.prisma.platformLink.create({ data: { userId, platform: linkData.platform, username: linkData.username, url, displayOrder: (maxOrder._max.displayOrder ?? -1) + 1 } })
}

export async function updatePlatformLink(app: FastifyInstance, userId: string, id: string, linkData: any) {

Check warning on line 58 in apps/backend/src/services/profileService.ts

View workflow job for this annotation

GitHub Actions / backend-ci

Missing return type on function
const existing = await app.prisma.platformLink.findFirst({ where: { id, userId } })
if (!existing) return null
if (!existing) {return null}
const url = linkData.url || getProfileUrl(linkData.platform, linkData.username)
return app.prisma.platformLink.update({ where: { id }, data: { platform: linkData.platform, username: linkData.username, url } })
}

export async function deletePlatformLink(app: FastifyInstance, userId: string, id: string) {

Check warning on line 65 in apps/backend/src/services/profileService.ts

View workflow job for this annotation

GitHub Actions / backend-ci

Missing return type on function
const existing = await app.prisma.platformLink.findFirst({ where: { id, userId } })
if (!existing) return false
if (!existing) {return false}
await app.prisma.platformLink.delete({ where: { id } })
return true
}

export async function reorderLinks(app: FastifyInstance, userId: string, links: Array<{ id: string; displayOrder: number }>) {

Check warning on line 72 in apps/backend/src/services/profileService.ts

View workflow job for this annotation

GitHub Actions / backend-ci

Missing return type on function
await app.prisma.$transaction(links.map((link) => app.prisma.platformLink.updateMany({ where: { id: link.id, userId }, data: { displayOrder: link.displayOrder } })))
return { message: 'Links reordered' }
}
2 changes: 1 addition & 1 deletion apps/backend/src/utils/validators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPlatform } from '@devcard/shared/src/platforms';
import { getPlatform } from '@devcard/shared';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not visible in checks.

import { z } from 'zod';

export const updateProfileSchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"types": "./src/index.ts",
"scripts": {
"build": "tsc",
"lint": "eslint src/",
Expand Down