mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add create folder policy api
This commit is contained in:
parent
7940c3f4ea
commit
2d757a4896
4 changed files with 96 additions and 8 deletions
|
|
@ -1,9 +1,11 @@
|
|||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm'
|
||||
import { User } from './user'
|
||||
|
||||
|
|
@ -36,9 +38,15 @@ export class FolderPolicy {
|
|||
@Column('int')
|
||||
minimumItems!: number
|
||||
|
||||
@Column('timestamptz')
|
||||
@CreateDateColumn({
|
||||
type: 'timestamptz',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
createdAt!: Date
|
||||
|
||||
@Column('timestamptz')
|
||||
@UpdateDateColumn({
|
||||
type: 'timestamptz',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
updatedAt!: Date
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
import { FolderPolicy } from '../../entity/folder_policy'
|
||||
import { FolderPolicy, FolderPolicyAction } from '../../entity/folder_policy'
|
||||
import {
|
||||
CreateFolderPolicyError,
|
||||
CreateFolderPolicySuccess,
|
||||
FolderPoliciesError,
|
||||
FolderPoliciesSuccess,
|
||||
MutationCreateFolderPolicyArgs,
|
||||
} from '../../generated/graphql'
|
||||
import { findFolderPoliciesByUserId } from '../../services/folder_policy'
|
||||
import {
|
||||
createFolderPolicy,
|
||||
findFolderPoliciesByUserId,
|
||||
} from '../../services/folder_policy'
|
||||
import { Merge } from '../../util'
|
||||
import { authorized } from '../../utils/gql-utils'
|
||||
|
||||
|
|
@ -21,3 +27,23 @@ export const folderPoliciesResolver = authorized<
|
|||
policies,
|
||||
}
|
||||
})
|
||||
|
||||
export const createFolderPolicyResolver = authorized<
|
||||
Merge<CreateFolderPolicySuccess, { policy: FolderPolicy }>,
|
||||
CreateFolderPolicyError,
|
||||
MutationCreateFolderPolicyArgs
|
||||
>(async (_, { input }, { uid }) => {
|
||||
const { folder, action, afterDays, minimumItems } = input
|
||||
|
||||
const policy = await createFolderPolicy({
|
||||
userId: uid,
|
||||
folder,
|
||||
action: action as unknown as FolderPolicyAction,
|
||||
afterDays,
|
||||
minimumItems: minimumItems ?? 0,
|
||||
})
|
||||
|
||||
return {
|
||||
policy,
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
import { createHmac } from 'crypto'
|
||||
import { isError } from 'lodash'
|
||||
import { FolderPolicy } from '../entity/folder_policy'
|
||||
import { Highlight } from '../entity/highlight'
|
||||
import { LibraryItem } from '../entity/library_item'
|
||||
import {
|
||||
|
|
@ -53,7 +52,10 @@ import {
|
|||
saveDiscoverArticleResolver,
|
||||
} from './discover_feeds'
|
||||
import { optInFeatureResolver } from './features'
|
||||
import { folderPoliciesResolver } from './folder_policy'
|
||||
import {
|
||||
createFolderPolicyResolver,
|
||||
folderPoliciesResolver,
|
||||
} from './folder_policy'
|
||||
import { highlightsResolver } from './highlight'
|
||||
import {
|
||||
hiddenHomeSectionResolver,
|
||||
|
|
@ -309,6 +311,7 @@ export const functionResolvers = {
|
|||
exportToIntegration: exportToIntegrationResolver,
|
||||
replyToEmail: replyToEmailResolver,
|
||||
refreshHome: refreshHomeResolver,
|
||||
createFolderPolicy: createFolderPolicyResolver,
|
||||
},
|
||||
Query: {
|
||||
me: getMeUserResolver,
|
||||
|
|
@ -884,4 +887,5 @@ export const functionResolvers = {
|
|||
...resultResolveTypeResolver('HiddenHomeSection'),
|
||||
...resultResolveTypeResolver('Highlights'),
|
||||
...resultResolveTypeResolver('FolderPolicies'),
|
||||
...resultResolveTypeResolver('CreateFolderPolicy'),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
import { expect } from 'chai'
|
||||
import { FolderPolicyAction } from '../../src/entity/folder_policy'
|
||||
import { User } from '../../src/entity/user'
|
||||
import { createFolderPolicy } from '../../src/services/folder_policy'
|
||||
import { FolderPolicy } from '../../src/generated/graphql'
|
||||
import {
|
||||
createFolderPolicy,
|
||||
deleteFolderPolicy,
|
||||
findFolderPolicyById,
|
||||
} from '../../src/services/folder_policy'
|
||||
import { deleteUser } from '../../src/services/user'
|
||||
import { createTestUser } from '../db'
|
||||
import { graphqlRequest, loginAndGetAuthToken } from '../util'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('Folder Policy API', () => {
|
||||
let loginUser: User
|
||||
|
|
@ -54,6 +59,51 @@ describe('Folder Policy API', () => {
|
|||
const policies = res.body.data.folderPolicies.policies as any[]
|
||||
expect(policies).to.have.lengthOf(1)
|
||||
expect(policies[0].id).to.equal(existingPolicy.id)
|
||||
|
||||
await deleteFolderPolicy(existingPolicy.id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Create Folder Policy', () => {
|
||||
const mutation = `
|
||||
mutation CreateFolderPolicy($input: CreateFolderPolicyInput!) {
|
||||
createFolderPolicy(input: $input) {
|
||||
... on CreateFolderPolicySuccess {
|
||||
policy {
|
||||
id
|
||||
folder
|
||||
action
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
... on CreateFolderPolicyError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
it('should create a folder policy', async () => {
|
||||
const input = {
|
||||
folder: 'test-folder',
|
||||
action: FolderPolicyAction.ARCHIVE,
|
||||
afterDays: 30,
|
||||
minimumItems: 10,
|
||||
}
|
||||
|
||||
const res = await graphqlRequest(mutation, authToken, { input }).expect(
|
||||
200
|
||||
)
|
||||
|
||||
const createdPolicy = res.body.data.createFolderPolicy
|
||||
.policy as FolderPolicy
|
||||
|
||||
const policy = await findFolderPolicyById(createdPolicy.id)
|
||||
expect(policy).to.exist
|
||||
expect(policy?.folder).to.equal(input.folder)
|
||||
|
||||
await deleteFolderPolicy(createdPolicy.id)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue