Skip to content

Commit f913b30

Browse files
committed
Moved a type to be shared for api endpoints
1 parent f6ed29d commit f913b30

3 files changed

Lines changed: 11 additions & 17 deletions

File tree

app/utils/atproto/likes.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { FetchError } from 'ofetch'
22
import { handleAuthError } from '~/utils/atproto/helpers'
3-
4-
// TODO: I need to share a type with the backend likes service
5-
export type PackageLikes = {
6-
totalLikes: number
7-
userHasLiked: boolean
8-
}
3+
import type { PackageLikes } from '#shared/types/social'
94

105
export type LikeResult = { success: true; data: PackageLikes } | { success: false; error: Error }
116

server/utils/atproto/utils/likes.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
import { $nsid as likeNsid } from '#shared/types/lexicons/dev/npmx/feed/like.defs'
22
import type { Backlink } from '#shared/utils/constellation'
33

4-
/**
5-
* Likes for a npm package on npmx
6-
*/
7-
export type PackageLikes = {
8-
// The total likes found for the package
9-
totalLikes: number
10-
// If the logged in user has liked the package, false if not logged in
11-
userHasLiked: boolean
12-
}
13-
144
//Cache keys and helpers
155
const CACHE_PREFIX = 'atproto-likes:'
166
const CACHE_PACKAGE_TOTAL_KEY = (packageName: string) => `${CACHE_PREFIX}${packageName}:total`
@@ -88,7 +78,7 @@ export class PackageLikesUtils {
8878
* @param usersDid
8979
* @returns
9080
*/
91-
async getLikes(packageName: string, usersDid?: string | undefined) {
81+
async getLikes(packageName: string, usersDid?: string | undefined): Promise<PackageLikes> {
9282
//TODO: May need to do some clean up on the package name, and maybe even hash it? some of the charcteres may be a bit odd as keys
9383
const totalLikesKey = CACHE_PACKAGE_TOTAL_KEY(packageName)
9484
const subjectRef = PACKAGE_SUBJECT_REF(packageName)

shared/types/social.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Likes for a npm package on npmx
3+
*/
4+
export type PackageLikes = {
5+
// The total likes found for the package
6+
totalLikes: number
7+
// If the logged in user has liked the package, false if not logged in
8+
userHasLiked: boolean
9+
}

0 commit comments

Comments
 (0)