This commit is contained in:
Hongbo Wu
2024-06-18 11:01:00 +08:00
parent 1168d12018
commit 45986184c4
32 changed files with 332 additions and 247 deletions

View File

@ -1,13 +1,13 @@
import { logger } from '../utils/logger'
import { loadSummarizationChain } from 'langchain/chains'
import { ChatOpenAI } from '@langchain/openai'
import { loadSummarizationChain } from 'langchain/chains'
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter'
import { authTrx } from '../repository'
import { libraryItemRepository } from '../repository/library_item'
import { htmlToMarkdown } from '../utils/parser'
import { AISummary } from '../entity/AISummary'
import { LibraryItemState } from '../entity/library_item'
import { authTrx } from '../repository'
import { libraryItemRepository } from '../repository/library_item'
import { getAISummary } from '../services/ai-summaries'
import { logger } from '../utils/logger'
import { htmlToMarkdown } from '../utils/parser'
export interface AISummarizeJobData {
userId: string
@ -24,8 +24,9 @@ export const aiSummarize = async (jobData: AISummarizeJobData) => {
tx
.withRepository(libraryItemRepository)
.findById(jobData.libraryItemId),
undefined,
jobData.userId
{
uid: jobData.userId,
}
)
if (!libraryItem || libraryItem.state !== LibraryItemState.Succeeded) {
logger.info(
@ -84,8 +85,9 @@ export const aiSummarize = async (jobData: AISummarizeJobData) => {
summary: summary,
})
},
undefined,
jobData.userId
{
uid: jobData.userId,
}
)
} catch (err) {
console.log('error creating summary: ', err)

View File

@ -248,8 +248,9 @@ export const saveAttachmentJob = async (data: EmailJobData) => {
status: UploadFileStatus.Completed,
user: { id: user.id },
}),
undefined,
user.id
{
uid: user.id,
}
)
const uploadFileDetails = await getStorageFileDetails(

View File

@ -28,8 +28,9 @@ export const updateLabels = async (data: UpdateLabelsData) => {
WHERE id = $1`,
[data.libraryItemId]
),
undefined,
data.userId
{
uid: data.userId,
}
)
}
@ -46,7 +47,8 @@ export const updateHighlight = async (data: UpdateHighlightData) => {
WHERE id = $1`,
[data.libraryItemId]
),
undefined,
data.userId
{
uid: data.userId,
}
)
}

View File

@ -1,4 +1,5 @@
import * as httpContext from 'express-http-context2'
import { DatabaseError } from 'pg'
import {
EntityManager,
EntityTarget,
@ -7,7 +8,6 @@ import {
QueryFailedError,
Repository,
} from 'typeorm'
import { DatabaseError } from 'pg'
import { appDataSource } from '../data_source'
import { Claims } from '../resolvers/types'
import { SetClaimsRole } from '../utils/dictionary'
@ -59,12 +59,19 @@ export const setClaims = async (
])
}
interface AuthTrxOptions {
entityManager?: EntityManager
uid?: string
userRole?: string
}
export const authTrx = async <T>(
fn: (manager: EntityManager) => Promise<T>,
em = appDataSource.manager,
uid?: string,
userRole?: string
options: AuthTrxOptions = {}
): Promise<T> => {
const entityManage = options.entityManager || appDataSource.manager
let { uid, userRole } = options
// if uid and dbRole are not passed in, then get them from the claims
if (!uid && !userRole) {
const claims: Claims | undefined = httpContext.get('claims')
@ -72,7 +79,7 @@ export const authTrx = async <T>(
userRole = claims?.userRole
}
return em.transaction(async (tx) => {
return entityManage.transaction(async (tx) => {
await setClaims(tx, uid, userRole)
return fn(tx)
})

View File

@ -11,6 +11,7 @@ import {
EXISTING_NEWSLETTER_FOLDER,
NewsletterEmail,
} from '../entity/newsletter_email'
import { Post } from '../entity/post'
import { PublicItem } from '../entity/public_item'
import { Recommendation } from '../entity/recommendation'
import {

View File

@ -82,8 +82,9 @@ export function pageRouter() {
status: UploadFileStatus.Initialized,
contentType: 'application/pdf',
}),
undefined,
claims.uid
{
uid: claims.uid,
}
)
const uploadFilePathName = generateUploadFilePathName(

View File

@ -67,8 +67,9 @@ export function emailAttachmentRouter() {
contentType,
user: { id: user.id },
}),
undefined,
user.id
{
uid: user.id,
}
)
if (uploadFileData.id) {

View File

@ -47,8 +47,9 @@ export function webhooksServiceRouter() {
.andWhere(':eventType = ANY(event_types)', { eventType })
.andWhere('enabled = true')
.getMany(),
undefined,
userId
{
uid: userId,
}
)
if (webhooks.length <= 0) {

View File

@ -53,8 +53,9 @@ export function textToSpeechRouter() {
state,
})
},
undefined,
userId
{
uid: userId,
}
)
res.send('OK')

View File

@ -27,8 +27,9 @@ export const getAISummary = async (data: {
})
}
},
undefined,
data.userId
{
uid: data.userId,
}
)
return aiSummary ?? undefined
}

View File

@ -27,8 +27,9 @@ export const findApiKeys = async (
createdAt: 'DESC',
},
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -36,9 +37,7 @@ export const deleteApiKey = async (
criteria: string[] | FindOptionsWhere<ApiKey>,
userId: string
) => {
return authTrx(
async (t) => t.getRepository(ApiKey).delete(criteria),
undefined,
userId
)
return authTrx(async (t) => t.getRepository(ApiKey).delete(criteria), {
uid: userId,
})
}

View File

@ -188,7 +188,9 @@ const validateInvite = async (
const numMembers = await authTrx(
(t) =>
t.getRepository(GroupMembership).countBy({ invite: { id: invite.id } }),
entityManager
{
entityManager,
}
)
if (numMembers >= invite.maxMembers) {
logger.info('rejecting invite, too many users', { invite, numMembers })

View File

@ -1,9 +1,9 @@
import { OpenAI } from '@langchain/openai'
import { PromptTemplate } from '@langchain/core/prompts'
import { OpenAI } from '@langchain/openai'
import { authTrx } from '../repository'
import { libraryItemRepository } from '../repository/library_item'
import { htmlToMarkdown } from '../utils/parser'
import { OPENAI_MODEL } from '../utils/ai'
import { htmlToMarkdown } from '../utils/parser'
export const explainText = async (
userId: string,
@ -20,8 +20,9 @@ export const explainText = async (
const libraryItem = await authTrx(
async (tx) =>
tx.withRepository(libraryItemRepository).findById(libraryItemId),
undefined,
userId
{
uid: userId,
}
)
if (!libraryItem) {

View File

@ -2,13 +2,12 @@ import * as jwt from 'jsonwebtoken'
import { DeepPartial, FindOptionsWhere, IsNull, Not } from 'typeorm'
import { appDataSource } from '../data_source'
import { Feature } from '../entity/feature'
import { LibraryItem } from '../entity/library_item'
import { Subscription, SubscriptionStatus } from '../entity/subscription'
import { env } from '../env'
import { OptInFeatureErrorCode } from '../generated/graphql'
import { authTrx, getRepository } from '../repository'
import { logger } from '../utils/logger'
import { OptInFeatureErrorCode } from '../generated/graphql'
import { Subscription, SubscriptionStatus } from '../entity/subscription'
import { libraryItemRepository } from '../repository/library_item'
import { LibraryItem } from '../entity/library_item'
const MAX_ULTRA_REALISTIC_USERS = 1500
const MAX_YOUTUBE_TRANSCRIPT_USERS = 500
@ -182,8 +181,9 @@ export const userDigestEligible = async (uid: string): Promise<boolean> => {
where: { user: { id: uid }, status: SubscriptionStatus.Active },
})
},
undefined,
uid
{
uid,
}
)
const libraryItemsCount = await authTrx(
@ -192,8 +192,9 @@ export const userDigestEligible = async (uid: string): Promise<boolean> => {
where: { user: { id: uid } },
})
},
undefined,
uid
{
uid,
}
)
return subscriptionsCount >= 2 && libraryItemsCount >= 10

View File

@ -50,8 +50,9 @@ export const createHighlights = async (
return authTrx(
async (tx) =>
tx.withRepository(highlightRepository).createAndSaves(highlights),
undefined,
userId
{
uid: userId,
}
)
}
@ -73,8 +74,9 @@ export const createHighlight = async (
},
})
},
undefined,
userId
{
uid: userId,
}
)
const data = deepDelete(newHighlight, columnsToDelete)
@ -221,8 +223,9 @@ export const deleteHighlightById = async (
await highlightRepo.delete(highlightId)
return highlight
},
undefined,
userId
{
uid: userId,
}
)
await enqueueUpdateHighlight({
@ -239,8 +242,9 @@ export const deleteHighlightsByIds = async (
) => {
await authTrx(
async (tx) => tx.getRepository(Highlight).delete(highlightIds),
undefined,
userId
{
uid: userId,
}
)
}
@ -255,8 +259,9 @@ export const findHighlightById = async (
id: highlightId,
})
},
undefined,
userId
{
uid: userId,
}
)
}
@ -273,8 +278,9 @@ export const findHighlightsByLibraryItemId = async (
labels: true,
},
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -321,7 +327,8 @@ export const searchHighlights = async (
return queryBuilder.getMany()
},
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -48,7 +48,8 @@ export const findUnseenPublicItems = async (
.take(options.limit)
.skip(options.offset)
.getMany(),
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -27,11 +27,9 @@ export const deleteIntegrations = async (
userId: string,
criteria: string[] | FindOptionsWhere<Integration>
) => {
return authTrx(
async (t) => t.getRepository(Integration).delete(criteria),
undefined,
userId
)
return authTrx(async (t) => t.getRepository(Integration).delete(criteria), {
uid: userId,
})
}
export const removeIntegration = async (
@ -40,8 +38,9 @@ export const removeIntegration = async (
) => {
return authTrx(
async (t) => t.getRepository(Integration).remove(integration),
undefined,
userId
{
uid: userId,
}
)
}
@ -55,8 +54,9 @@ export const findIntegration = async (
...where,
user: { id: userId },
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -71,8 +71,9 @@ export const findIntegrationByName = async (name: string, userId: string) => {
})
.andWhere('LOWER(name) = LOWER(:name)', { name }) // case insensitive
.getOne(),
undefined,
userId
{
uid: userId,
}
)
}
@ -86,8 +87,9 @@ export const findIntegrations = async (
...where,
user: { id: userId },
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -101,8 +103,9 @@ export const saveIntegration = async (
const newIntegration = await repo.save(integration)
return repo.findOneByOrFail({ id: newIntegration.id })
},
undefined,
userId
{
uid: userId,
}
)
}
@ -113,7 +116,8 @@ export const updateIntegration = async (
) => {
return authTrx(
async (t) => t.getRepository(Integration).update(id, integration),
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -72,8 +72,9 @@ export const findOrCreateLabels = async (
user: { id: userId },
})
},
undefined,
userId
{
uid: userId,
}
)
}
@ -156,8 +157,9 @@ export const saveLabelsInLibraryItem = async (
}))
)
},
undefined,
userId
{
uid: userId,
}
)
if (source === 'user') {
@ -197,8 +199,9 @@ export const addLabelsToLibraryItem = async (
[libraryItemId, source, labelIds]
)
},
undefined,
userId
{
uid: userId,
}
)
// update labels in library item
@ -265,8 +268,9 @@ export const findLabelsByIds = async (
user: { id: userId },
})
},
undefined,
userId
{
uid: userId,
}
)
}
@ -278,8 +282,9 @@ export const createLabel = async (
return authTrx(
(t) =>
t.withRepository(labelRepository).createLabel({ name, color }, userId),
undefined,
userId
{
uid: userId,
}
)
}
@ -289,8 +294,9 @@ export const deleteLabels = async (
) => {
return authTrx(
async (t) => t.withRepository(labelRepository).delete(criteria),
undefined,
userId
{
uid: userId,
}
)
}
@ -326,8 +332,9 @@ export const updateLabel = async (
return repo.findOneByOrFail({ id })
},
undefined,
userId
{
uid: userId,
}
)
const libraryItemIds = await findLibraryItemIdsByLabelId(id, userId)
@ -348,8 +355,9 @@ export const findLabelsByUserId = async (userId: string): Promise<Label[]> => {
where: { user: { id: userId } },
order: { position: 'ASC' },
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -359,8 +367,9 @@ export const findLabelById = async (id: string, userId: string) => {
tx
.withRepository(labelRepository)
.findOneBy({ id, user: { id: userId } }),
undefined,
userId
{
uid: userId,
}
)
}
@ -380,7 +389,8 @@ export const findLabelsByLibraryItemId = async (
source: el.source,
}))
},
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -707,8 +707,9 @@ export const createSearchQueryBuilder = (
export const countLibraryItems = async (args: SearchArgs, userId: string) => {
return authTrx(
async (tx) => createSearchQueryBuilder(args, userId, tx).getCount(),
undefined,
userId
{
uid: userId,
}
)
}
@ -729,8 +730,9 @@ export const searchLibraryItems = async (
.skip(from)
.take(size)
.getMany(),
undefined,
userId
{
uid: userId,
}
)
}
@ -774,8 +776,9 @@ export const findRecentLibraryItems = async (
.take(limit)
.skip(offset)
.getMany(),
undefined,
userId
{
uid: userId,
}
)
}
@ -798,8 +801,9 @@ export const findLibraryItemsByIds = async (
.select(selectColumns)
.where('library_item.id IN (:...ids)', { ids })
.getMany(),
undefined,
userId
{
uid: userId,
}
)
}
@ -826,8 +830,9 @@ export const findLibraryItemById = async (
where: { id },
relations: options?.relations,
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -848,8 +853,9 @@ export const findLibraryItemByUrl = async (
.where('library_item.user_id = :userId', { userId })
.andWhere('md5(library_item.original_url) = md5(:url)', { url })
.getOne(),
undefined,
userId
{
uid: userId,
}
)
}
@ -889,8 +895,9 @@ export const softDeleteLibraryItem = async (
return itemRepo.findOneByOrFail({ id })
},
undefined,
userId
{
uid: userId,
}
)
await pubsub.entityDeleted(EntityType.ITEM, id, userId)
@ -924,8 +931,9 @@ export const updateLibraryItem = async (
return itemRepo.findOneByOrFail({ id })
},
undefined,
userId
{
uid: userId,
}
)
if (skipPubSub || libraryItem.state === LibraryItemState.Processing) {
@ -998,8 +1006,9 @@ export const updateLibraryItemReadingProgress = async (
`,
[id, topPercent, bottomPercent, anchorIndex]
),
undefined,
userId
{
uid: userId,
}
)) as [LibraryItem[], number]
if (result[1] === 0) {
return null
@ -1017,8 +1026,9 @@ export const createLibraryItems = async (
): Promise<LibraryItem[]> => {
return authTrx(
async (tx) => tx.withRepository(libraryItemRepository).save(libraryItems),
undefined,
userId
{
uid: userId,
}
)
}
@ -1094,8 +1104,9 @@ export const createOrUpdateLibraryItem = async (
// create or update library item
return repo.upsertLibraryItemById(libraryItem)
},
undefined,
userId
{
uid: userId,
}
)
// set recently saved item in redis if redis is enabled
@ -1171,8 +1182,9 @@ export const countBySavedAt = async (
endDate,
})
.getCount(),
undefined,
userId
{
uid: userId,
}
)
}
@ -1253,8 +1265,9 @@ export const batchUpdateLibraryItems = async (
const libraryItemIds = await authTrx(
async (tx) => getLibraryItemIds(userId, tx),
undefined,
userId
{
uid: userId,
}
)
// add labels to library items
for (const libraryItemId of libraryItemIds) {
@ -1266,8 +1279,9 @@ export const batchUpdateLibraryItems = async (
case BulkActionType.MarkAsRead: {
const libraryItemIds = await authTrx(
async (tx) => getLibraryItemIds(userId, tx),
undefined,
userId
{
uid: userId,
}
)
// update reading progress for library items
for (const libraryItemId of libraryItemIds) {
@ -1301,16 +1315,18 @@ export const batchUpdateLibraryItems = async (
const libraryItemIds = await getLibraryItemIds(userId, tx, true)
await tx.getRepository(LibraryItem).update(libraryItemIds, values)
},
undefined,
userId
{
uid: userId,
}
)
}
export const deleteLibraryItemById = async (id: string, userId?: string) => {
return authTrx(
async (tx) => tx.withRepository(libraryItemRepository).delete(id),
undefined,
userId
{
uid: userId,
}
)
}
@ -1321,8 +1337,9 @@ export const deleteLibraryItems = async (
return authTrx(
async (tx) =>
tx.withRepository(libraryItemRepository).delete(items.map((i) => i.id)),
undefined,
userId
{
uid: userId,
}
)
}
@ -1332,8 +1349,9 @@ export const deleteLibraryItemByUrl = async (url: string, userId: string) => {
tx
.withRepository(libraryItemRepository)
.delete({ originalUrl: url, user: { id: userId } }),
undefined,
userId
{
uid: userId,
}
)
}
@ -1343,8 +1361,9 @@ export const deleteLibraryItemsByUserId = async (userId: string) => {
tx.withRepository(libraryItemRepository).delete({
user: { id: userId },
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -1403,8 +1422,9 @@ export const findLibraryItemIdsByLabelId = async (
return result.map((r) => r.library_item_id)
},
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -15,8 +15,10 @@ export const addPopularRead = async (
tx
.withRepository(libraryItemRepository)
.createByPopularRead(name, userId),
entityManager,
userId
{
entityManager,
uid: userId,
}
)
}

View File

@ -1,6 +1,6 @@
import { Profile } from '../entity/profile'
import { User } from '../entity/user'
import { getRepository } from '../repository'
import { authTrx, getRepository } from '../repository'
export const findProfile = async (user: User): Promise<Profile | null> => {
return getRepository(Profile).findOneBy({ user: { id: user.id } })

View File

@ -23,8 +23,9 @@ export const saveReceivedEmail = async (
user: { id: userId },
replyTo,
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -38,16 +39,18 @@ export const updateReceivedEmail = async (
t
.getRepository(ReceivedEmail)
.update({ id, user: { id: userId } }, { type }),
undefined,
userId
{
uid: userId,
}
)
}
export const deleteReceivedEmail = async (id: string, userId: string) => {
return authTrx(
(t) => t.getRepository(ReceivedEmail).delete({ id, user: { id: userId } }),
undefined,
userId
{
uid: userId,
}
)
}
@ -55,7 +58,8 @@ export const findReceivedEmailById = async (id: string, userId: string) => {
return authTrx(
(t) =>
t.getRepository(ReceivedEmail).findOneBy({ id, user: { id: userId } }),
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -116,8 +116,9 @@ export const createRecommendation = async (
) => {
return authTrx(
async (tx) => tx.getRepository(Recommendation).save(recommendation),
undefined,
userId
{
uid: userId,
}
)
}
@ -134,7 +135,8 @@ export const findRecommendationsByLibraryItemId = async (
recommender: true,
},
}),
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -28,8 +28,9 @@ export const createRule = async (
...rule,
user: { id: userId },
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -41,16 +42,18 @@ export const deleteRule = async (id: string, userId: string) => {
await repo.delete(id)
return rule
},
undefined,
userId
{
uid: userId,
}
)
}
export const deleteRules = async (userId: string) => {
return authTrx(
(t) => t.getRepository(Rule).delete({ user: { id: userId } }),
undefined,
userId
{
uid: userId,
}
)
}
@ -72,7 +75,8 @@ export const markRuleAsFailed = async (id: string, userId: string) => {
t.getRepository(Rule).update(id, {
failedAt: new Date(),
}),
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -43,8 +43,9 @@ export const updateContentForFileItem = async (msg: UpdateContentMessage) => {
.innerJoinAndSelect('item.uploadFile', 'file')
.where('file.id = :fileId', { fileId })
.getOne(),
undefined,
uploadFile.user.id
{
uid: uploadFile.user.id,
}
)
if (!libraryItem) {
logger.info(`No upload file found for id: ${fileId}`)

View File

@ -59,8 +59,9 @@ export const setFileUploadComplete = async (id: string, userId?: string) => {
return repo.findOneByOrFail({ id })
},
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -17,17 +17,16 @@ export const deleteUser = async (userId: string) => {
async (t) => {
await t.withRepository(userRepository).delete(userId)
},
undefined,
userId
{
uid: userId,
}
)
}
export const updateUser = async (userId: string, update: Partial<User>) => {
return authTrx(
async (t) => t.getRepository(User).update(userId, update),
undefined,
userId
)
return authTrx(async (t) => t.getRepository(User).update(userId, update), {
uid: userId,
})
}
export const softDeleteUser = async (userId: string) => {
@ -51,8 +50,9 @@ export const softDeleteUser = async (userId: string) => {
sourceUserId: `deleted_user_${userId}`,
})
},
undefined,
userId
{
uid: userId,
}
)
}
@ -67,21 +67,15 @@ export const findUsersByIds = async (ids: string[]): Promise<User[]> => {
export const deleteUsers = async (
criteria: FindOptionsWhere<User> | string[]
) => {
return authTrx(
async (t) => t.getRepository(User).delete(criteria),
undefined,
undefined,
SetClaimsRole.ADMIN
)
return authTrx(async (t) => t.getRepository(User).delete(criteria), {
userRole: SetClaimsRole.ADMIN,
})
}
export const createUsers = async (users: DeepPartial<User>[]) => {
return authTrx(
async (t) => t.getRepository(User).save(users),
undefined,
undefined,
SetClaimsRole.ADMIN
)
return authTrx(async (t) => t.getRepository(User).save(users), {
userRole: SetClaimsRole.ADMIN,
})
}
export const batchDelete = async (criteria: FindOptionsWhere<User>) => {
@ -95,7 +89,7 @@ export const batchDelete = async (criteria: FindOptionsWhere<User>) => {
const sql = `
-- Set batch size
DO $$
DECLARE
DECLARE
batch_size INT := ${batchSize};
user_ids UUID[];
BEGIN
@ -103,7 +97,7 @@ export const batchDelete = async (criteria: FindOptionsWhere<User>) => {
FOR i IN 0..CEIL((${userCountSql}) * 1.0 / batch_size) - 1 LOOP
-- GET batch of user ids
${userSubQuery} LIMIT batch_size;
-- Loop through batches of items
FOR j IN 0..CEIL((SELECT COUNT(1) FROM omnivore.library_item WHERE user_id = ANY(user_ids)) * 1.0 / batch_size) - 1 LOOP
-- Delete batch of items
@ -122,12 +116,9 @@ export const batchDelete = async (criteria: FindOptionsWhere<User>) => {
END $$
`
return authTrx(
async (t) => t.query(sql),
undefined,
undefined,
SetClaimsRole.ADMIN
)
return authTrx(async (t) => t.query(sql), {
userRole: SetClaimsRole.ADMIN,
})
}
export const sendPushNotifications = async (
@ -160,7 +151,8 @@ export const findUserAndPersonalization = async (id: string) => {
userPersonalization: true,
},
}),
undefined,
id
{
uid: id,
}
)
}

View File

@ -11,8 +11,9 @@ export const findDeviceTokenById = async (
return authTrx(
(t) =>
t.getRepository(UserDeviceToken).findOneBy({ id, user: { id: userId } }),
undefined,
userId
{
uid: userId,
}
)
}
@ -25,8 +26,9 @@ export const findDeviceTokenByToken = async (
t
.getRepository(UserDeviceToken)
.findOneBy({ token, user: { id: userId } }),
undefined,
userId
{
uid: userId,
}
)
}
@ -38,8 +40,9 @@ export const findDeviceTokensByUserId = async (
t.getRepository(UserDeviceToken).findBy({
user: { id: userId },
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -61,8 +64,9 @@ export const createDeviceToken = async (
token,
user: { id: userId },
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -95,7 +99,8 @@ export const deleteDeviceTokens = async (
async (t) => {
await t.getRepository(UserDeviceToken).delete(criteria)
},
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -12,8 +12,9 @@ export const findUserPersonalization = async (userId: string) => {
t.getRepository(UserPersonalization).findOneBy({
user: { id: userId },
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -23,8 +24,9 @@ export const deleteUserPersonalization = async (userId: string) => {
t.getRepository(UserPersonalization).delete({
user: { id: userId },
}),
undefined,
userId
{
uid: userId,
}
)
}
@ -34,8 +36,9 @@ export const saveUserPersonalization = async (
) => {
return authTrx(
(t) => t.getRepository(UserPersonalization).save(userPersonalization),
undefined,
userId
{
uid: userId,
}
)
}
@ -45,8 +48,9 @@ export const getShortcuts = async (userId: string): Promise<Shortcut[]> => {
t.getRepository(UserPersonalization).findOneBy({
user: { id: userId },
}),
undefined,
userId
{
uid: userId,
}
)
if (personalization?.shortcuts) {
return personalization?.shortcuts as Shortcut[]
@ -67,8 +71,9 @@ export const resetShortcuts = async (userId: string): Promise<boolean> => {
})
.execute()
},
undefined,
userId
{
uid: userId,
}
)
if (!result) {
throw Error('Could not update shortcuts')
@ -90,8 +95,9 @@ export const setShortcuts = async (
shortcuts: shortcuts,
}
),
undefined,
userId
{
uid: userId,
}
)
if (!result.affected || result.affected < 1) {
throw Error('Could not update shortcuts')

View File

@ -7,11 +7,10 @@ export const createWebhooks = async (
userId?: string,
entityManager?: EntityManager
) => {
return authTrx(
(tx) => tx.getRepository(Webhook).save(webhooks),
entityManager,
userId
)
return authTrx((tx) => tx.getRepository(Webhook).save(webhooks), {
entityManager: entityManager,
uid: userId,
})
}
export const createWebhook = async (
@ -19,18 +18,18 @@ export const createWebhook = async (
userId?: string,
entityManager?: EntityManager
) => {
return authTrx(
(tx) => tx.getRepository(Webhook).save(webhook),
entityManager,
userId
)
return authTrx((tx) => tx.getRepository(Webhook).save(webhook), {
entityManager: entityManager,
uid: userId,
})
}
export const findWebhooks = async (userId: string) => {
return authTrx(
(tx) => tx.getRepository(Webhook).findBy({ user: { id: userId } }),
undefined,
userId
{
uid: userId,
}
)
}
@ -45,16 +44,18 @@ export const findWebhooksByEventType = async (
enabled: true,
eventTypes: ArrayContains([eventType]),
}),
undefined,
userId
{
uid: userId,
}
)
}
export const findWebhookById = async (id: string, userId: string) => {
return authTrx(
(tx) => tx.getRepository(Webhook).findOneBy({ id, user: { id: userId } }),
undefined,
userId
{
uid: userId,
}
)
}
@ -66,7 +67,8 @@ export const deleteWebhook = async (id: string, userId: string) => {
await repo.delete(id)
return webhook
},
undefined,
userId
{
uid: userId,
}
)
}

View File

@ -158,8 +158,9 @@ export const saveLabelsInLibraryItem = async (
}))
)
},
undefined,
userId
{
uid: userId,
}
)
// update labels in library item
@ -184,8 +185,9 @@ export const createHighlight = async (
},
})
},
undefined,
userId
{
uid: userId,
}
)
const job = await enqueueUpdateHighlight({

View File

@ -24,8 +24,9 @@ describe('create user', () => {
const user = await createTestUser('filter_user')
const filters = await authTrx(
(t) => t.getRepository(Filter).findBy({ user: { id: user.id } }),
undefined,
user.id
{
uid: user.id,
}
)
expect(filters).not.to.be.empty