feat(medusa): Allow to filter the batch jobs with nullable date (#1747)
This commit is contained in:
1 parent
fb7abbf407
commit
c0f624ad3b
4 files changed
+151
-15
No files matched your search
@@ -1,6 +1,88 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`/admin/batch-jobs GET /admin/batch-jobs lists batch jobs created by the user 1`] = `
|
exports[`/admin/batch-jobs GET /admin/batch-jobs lists batch jobs created by the user 1`] = `
|
||||||
|
Object {
|
||||||
|
"batch_jobs": Array [
|
||||||
|
Object {
|
||||||
|
"canceled_at": null,
|
||||||
|
"completed_at": "2022-06-27T22:00:00.000Z",
|
||||||
|
"confirmed_at": null,
|
||||||
|
"context": Object {},
|
||||||
|
"created_at": Any<String>,
|
||||||
|
"created_by": "admin_user",
|
||||||
|
"deleted_at": null,
|
||||||
|
"dry_run": false,
|
||||||
|
"failed_at": null,
|
||||||
|
"id": "job_5",
|
||||||
|
"pre_processed_at": null,
|
||||||
|
"processing_at": null,
|
||||||
|
"result": null,
|
||||||
|
"status": "completed",
|
||||||
|
"type": "product-export",
|
||||||
|
"updated_at": Any<String>,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"canceled_at": null,
|
||||||
|
"completed_at": null,
|
||||||
|
"confirmed_at": null,
|
||||||
|
"context": Object {},
|
||||||
|
"created_at": Any<String>,
|
||||||
|
"created_by": "admin_user",
|
||||||
|
"deleted_at": null,
|
||||||
|
"dry_run": false,
|
||||||
|
"failed_at": null,
|
||||||
|
"id": "job_3",
|
||||||
|
"pre_processed_at": null,
|
||||||
|
"processing_at": null,
|
||||||
|
"result": null,
|
||||||
|
"status": "created",
|
||||||
|
"type": "product-export",
|
||||||
|
"updated_at": Any<String>,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"canceled_at": null,
|
||||||
|
"completed_at": null,
|
||||||
|
"confirmed_at": null,
|
||||||
|
"context": Object {},
|
||||||
|
"created_at": Any<String>,
|
||||||
|
"created_by": "admin_user",
|
||||||
|
"deleted_at": null,
|
||||||
|
"dry_run": false,
|
||||||
|
"failed_at": null,
|
||||||
|
"id": "job_2",
|
||||||
|
"pre_processed_at": null,
|
||||||
|
"processing_at": null,
|
||||||
|
"result": null,
|
||||||
|
"status": "created",
|
||||||
|
"type": "product-export",
|
||||||
|
"updated_at": Any<String>,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"canceled_at": null,
|
||||||
|
"completed_at": null,
|
||||||
|
"confirmed_at": null,
|
||||||
|
"context": Object {},
|
||||||
|
"created_at": Any<String>,
|
||||||
|
"created_by": "admin_user",
|
||||||
|
"deleted_at": null,
|
||||||
|
"dry_run": false,
|
||||||
|
"failed_at": null,
|
||||||
|
"id": "job_1",
|
||||||
|
"pre_processed_at": null,
|
||||||
|
"processing_at": null,
|
||||||
|
"result": null,
|
||||||
|
"status": "created",
|
||||||
|
"type": "product-export",
|
||||||
|
"updated_at": Any<String>,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"count": 4,
|
||||||
|
"limit": 10,
|
||||||
|
"offset": 0,
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`/admin/batch-jobs GET /admin/batch-jobs lists batch jobs created by the user and where completed_at is null 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"batch_jobs": Array [
|
"batch_jobs": Array [
|
||||||
Object {
|
Object {
|
||||||
|
|||||||
@@ -43,6 +43,13 @@ const setupJobDb = async (dbConnection) => {
|
|||||||
status: "awaiting_confirmation",
|
status: "awaiting_confirmation",
|
||||||
created_by: "member-user",
|
created_by: "member-user",
|
||||||
})
|
})
|
||||||
|
await simpleBatchJobFactory(dbConnection, {
|
||||||
|
id: "job_5",
|
||||||
|
type: "product-export",
|
||||||
|
status: "completed",
|
||||||
|
completed_at: "2022-06-27T22:00:00.000Z",
|
||||||
|
created_by: "admin_user",
|
||||||
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
throw err
|
throw err
|
||||||
@@ -80,21 +87,60 @@ describe("/admin/batch-jobs", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
const response = await api.get("/admin/batch-jobs", adminReqConfig)
|
const response = await api.get("/admin/batch-jobs", adminReqConfig)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.batch_jobs.length).toEqual(4)
|
||||||
|
expect(response.data).toMatchSnapshot({
|
||||||
|
batch_jobs: [
|
||||||
|
{
|
||||||
|
id: "job_5",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
created_by: "admin_user"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "job_3",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
created_by: "admin_user"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "job_2",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
created_by: "admin_user"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "job_1",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
created_by: "admin_user"
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("lists batch jobs created by the user and where completed_at is null ", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
const response = await api.get("/admin/batch-jobs?completed_at=null", adminReqConfig)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
expect(response.data.batch_jobs.length).toEqual(3)
|
expect(response.data.batch_jobs.length).toEqual(3)
|
||||||
expect(response.data).toMatchSnapshot({
|
expect(response.data).toMatchSnapshot({
|
||||||
batch_jobs: [
|
batch_jobs: [
|
||||||
{
|
{
|
||||||
|
id: "job_3",
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
created_by: "admin_user"
|
created_by: "admin_user"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id: "job_2",
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
created_by: "admin_user"
|
created_by: "admin_user"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id: "job_1",
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
created_by: "admin_user"
|
created_by: "admin_user"
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import { Type } from "class-transformer"
|
import { Transform, Type } from "class-transformer"
|
||||||
import {
|
import {
|
||||||
IsArray,
|
IsArray,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString,
|
||||||
ValidateNested,
|
|
||||||
} from "class-validator"
|
} from "class-validator"
|
||||||
import { pickBy } from "lodash"
|
import { pickBy } from "lodash"
|
||||||
import BatchJobService from "../../../../services/batch-job"
|
import BatchJobService from "../../../../services/batch-job"
|
||||||
@@ -22,15 +21,15 @@ import { Request } from "express"
|
|||||||
* - (query) limit {string} The number of collections to return.
|
* - (query) limit {string} The number of collections to return.
|
||||||
* - (query) offset {string} The offset of collections to return.
|
* - (query) offset {string} The offset of collections to return.
|
||||||
* - (query) type {string | string[]} Filter by the batch type
|
* - (query) type {string | string[]} Filter by the batch type
|
||||||
* - (query) confirmed_at {DateComparisonOperator} Date comparison for when resulting collections was confirmed, i.e. less than, greater than etc.
|
* - (query) confirmed_at {DateComparisonOperator | null} Date comparison for when resulting collections was confirmed, i.e. less than, greater than etc.
|
||||||
* - (query) pre_processed_at {DateComparisonOperator} Date comparison for when resulting collections was pre processed, i.e. less than, greater than etc.
|
* - (query) pre_processed_at {DateComparisonOperator | null} Date comparison for when resulting collections was pre processed, i.e. less than, greater than etc.
|
||||||
* - (query) completed_at {DateComparisonOperator} Date comparison for when resulting collections was completed, i.e. less than, greater than etc.
|
* - (query) completed_at {DateComparisonOperator | null} Date comparison for when resulting collections was completed, i.e. less than, greater than etc.
|
||||||
* - (query) failed_at {DateComparisonOperator} Date comparison for when resulting collections was failed, i.e. less than, greater than etc.
|
* - (query) failed_at {DateComparisonOperator | null} Date comparison for when resulting collections was failed, i.e. less than, greater than etc.
|
||||||
* - (query) canceled_at {DateComparisonOperator} Date comparison for when resulting collections was canceled, i.e. less than, greater than etc.
|
* - (query) canceled_at {DateComparisonOperator | null} Date comparison for when resulting collections was canceled, i.e. less than, greater than etc.
|
||||||
* - (query) order {string} Order used when retrieving batch jobs
|
* - (query) order {string} Order used when retrieving batch jobs
|
||||||
* - (query) expand[] {string} (Comma separated) Which fields should be expanded in each order of the result.
|
* - (query) expand[] {string} (Comma separated) Which fields should be expanded in each order of the result.
|
||||||
* - (query) fields[] {string} (Comma separated) Which fields should be included in each order of the result.
|
* - (query) fields[] {string} (Comma separated) Which fields should be included in each order of the result.
|
||||||
* - (query) deleted_at {DateComparisonOperator} Date comparison for when resulting collections was deleted, i.e. less than, greater than etc.
|
* - (query) deleted_at {DateComparisonOperator | null} Date comparison for when resulting collections was deleted, i.e. less than, greater than etc.
|
||||||
* - (query) created_at {DateComparisonOperator} Date comparison for when resulting collections was created, i.e. less than, greater than etc.
|
* - (query) created_at {DateComparisonOperator} Date comparison for when resulting collections was created, i.e. less than, greater than etc.
|
||||||
* - (query) updated_at {DateComparisonOperator} Date comparison for when resulting collections was updated, i.e. less than, greater than etc.
|
* - (query) updated_at {DateComparisonOperator} Date comparison for when resulting collections was updated, i.e. less than, greater than etc.
|
||||||
* tags:
|
* tags:
|
||||||
@@ -102,31 +101,35 @@ export class AdminGetBatchParams extends AdminGetBatchPaginationParams {
|
|||||||
type?: string[]
|
type?: string[]
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@Transform(({ value }) => (value === "null" ? null : value))
|
||||||
@Type(() => DateComparisonOperator)
|
@Type(() => DateComparisonOperator)
|
||||||
confirmed_at?: DateComparisonOperator
|
confirmed_at?: DateComparisonOperator | null
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@Transform(({ value }) => (value === "null" ? null : value))
|
||||||
@Type(() => DateComparisonOperator)
|
@Type(() => DateComparisonOperator)
|
||||||
pre_processed_at?: DateComparisonOperator
|
pre_processed_at?: DateComparisonOperator | null
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@Transform(({ value }) => (value === "null" ? null : value))
|
||||||
@Type(() => DateComparisonOperator)
|
@Type(() => DateComparisonOperator)
|
||||||
completed_at?: DateComparisonOperator
|
completed_at?: DateComparisonOperator | null
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@Transform(({ value }) => (value === "null" ? null : value))
|
||||||
@Type(() => DateComparisonOperator)
|
@Type(() => DateComparisonOperator)
|
||||||
failed_at?: DateComparisonOperator
|
failed_at?: DateComparisonOperator | null
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@Transform(({ value }) => (value === "null" ? null : value))
|
||||||
@Type(() => DateComparisonOperator)
|
@Type(() => DateComparisonOperator)
|
||||||
canceled_at?: DateComparisonOperator
|
canceled_at?: DateComparisonOperator | null
|
||||||
|
|
||||||
@IsType([DateComparisonOperator])
|
@IsType([DateComparisonOperator])
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
created_at?: DateComparisonOperator
|
created_at?: DateComparisonOperator
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ValidateNested()
|
|
||||||
@Type(() => DateComparisonOperator)
|
@Type(() => DateComparisonOperator)
|
||||||
updated_at?: DateComparisonOperator
|
updated_at?: DateComparisonOperator
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
Selector,
|
Selector,
|
||||||
Writable,
|
Writable,
|
||||||
} from "../types/common"
|
} from "../types/common"
|
||||||
import { FindOperator, In, Raw } from "typeorm"
|
import { FindOperator, In, IsNull, Raw } from "typeorm"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to build TypeORM queries.
|
* Used to build TypeORM queries.
|
||||||
@@ -24,6 +24,11 @@ export function buildQuery<TWhereKeys, TEntity = unknown>(
|
|||||||
return acc
|
return acc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value === null) {
|
||||||
|
acc[key] = IsNull()
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
|
||||||
const subquery: {
|
const subquery: {
|
||||||
operator: "<" | ">" | "<=" | ">="
|
operator: "<" | ">" | "<=" | ">="
|
||||||
value: unknown
|
value: unknown
|
||||||
|
|||||||
Reference in new issue
Block a user