mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Eagerly load profile of the user
This commit is contained in:
parent
c3366c6238
commit
bce7afde50
3 changed files with 20 additions and 14 deletions
|
|
@ -40,7 +40,7 @@ export class User {
|
|||
@OneToMany(() => NewsletterEmail, (newsletterEmail) => newsletterEmail.user)
|
||||
newsletterEmails?: NewsletterEmail[]
|
||||
|
||||
@OneToOne(() => Profile, (profile) => profile.user)
|
||||
@OneToOne(() => Profile, (profile) => profile.user, { eager: true })
|
||||
profile!: Profile
|
||||
|
||||
@Column('varchar', { length: 255, nullable: true })
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
import { User } from '../../entity/user'
|
||||
import { getRepository } from '../../entity/utils'
|
||||
import { env } from '../../env'
|
||||
import {
|
||||
MutationSaveFileArgs,
|
||||
MutationSavePageArgs,
|
||||
|
|
@ -6,12 +9,11 @@ import {
|
|||
SaveErrorCode,
|
||||
SaveSuccess,
|
||||
} from '../../generated/graphql'
|
||||
import { saveFile } from '../../services/save_file'
|
||||
import { savePage } from '../../services/save_page'
|
||||
import { saveUrl } from '../../services/save_url'
|
||||
import { saveFile } from '../../services/save_file'
|
||||
import { authorized, userDataToUser } from '../../utils/helpers'
|
||||
import { analytics } from '../../utils/analytics'
|
||||
import { env } from '../../env'
|
||||
import { authorized, userDataToUser } from '../../utils/helpers'
|
||||
|
||||
export const savePageResolver = authorized<
|
||||
SaveSuccess,
|
||||
|
|
@ -51,7 +53,6 @@ export const saveUrlResolver = authorized<
|
|||
MutationSaveUrlArgs
|
||||
>(async (_, { input }, ctx) => {
|
||||
const {
|
||||
models,
|
||||
claims: { uid },
|
||||
} = ctx
|
||||
|
||||
|
|
@ -66,7 +67,9 @@ export const saveUrlResolver = authorized<
|
|||
},
|
||||
})
|
||||
|
||||
const user = userDataToUser(await models.user.get(uid))
|
||||
const user = await getRepository(User).findOneBy({
|
||||
id: uid,
|
||||
})
|
||||
if (!user) {
|
||||
return { errorCodes: [SaveErrorCode.Unauthorized] }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ interface PageSaveRequest {
|
|||
archivedAt?: Date | null
|
||||
labels?: Label[]
|
||||
priority?: 'low' | 'high'
|
||||
user?: User | null
|
||||
}
|
||||
|
||||
const SAVING_CONTENT = 'Your link is being saved...'
|
||||
|
|
@ -76,6 +77,7 @@ export const createPageSaveRequest = async ({
|
|||
archivedAt,
|
||||
priority,
|
||||
labels,
|
||||
user,
|
||||
}: PageSaveRequest): Promise<ArticleSavingRequest> => {
|
||||
try {
|
||||
validateUrl(url)
|
||||
|
|
@ -85,16 +87,17 @@ export const createPageSaveRequest = async ({
|
|||
errorCode: CreateArticleSavingRequestErrorCode.BadData,
|
||||
})
|
||||
}
|
||||
|
||||
const user = await getRepository(User).findOne({
|
||||
where: { id: userId },
|
||||
relations: ['profile'],
|
||||
})
|
||||
// if user is not specified, get it from the database
|
||||
if (!user) {
|
||||
console.log('User not found', userId)
|
||||
return Promise.reject({
|
||||
errorCode: CreateArticleSavingRequestErrorCode.BadData,
|
||||
user = await getRepository(User).findOneBy({
|
||||
id: userId,
|
||||
})
|
||||
if (!user) {
|
||||
console.log('User not found', userId)
|
||||
return Promise.reject({
|
||||
errorCode: CreateArticleSavingRequestErrorCode.BadData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// get priority by checking rate limit if not specified
|
||||
|
|
|
|||
Loading…
Reference in a new issue