refactor: clean code
This commit is contained in:
@@ -19,17 +19,18 @@ export const list = async (request: ListCertificateRequest) => {
|
||||
const perPage = request.perPage || 10;
|
||||
|
||||
const options: RecordListOptions = {
|
||||
sort: "-created",
|
||||
expand: "workflowId",
|
||||
filter: "deleted=null",
|
||||
sort: "-created",
|
||||
requestKey: null,
|
||||
};
|
||||
|
||||
if (request.state === "expireSoon") {
|
||||
options.filter = pb.filter("expireAt<{:expiredAt}", {
|
||||
expiredAt: dayjs().add(15, "d").toDate(),
|
||||
options.filter = pb.filter("expireAt<{:expiredAt} && deleted=null", {
|
||||
expiredAt: dayjs().add(20, "d").toDate(),
|
||||
});
|
||||
} else if (request.state === "expired") {
|
||||
options.filter = pb.filter("expireAt<={:expiredAt}", {
|
||||
options.filter = pb.filter("expireAt<={:expiredAt} && deleted=null", {
|
||||
expiredAt: new Date(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type RecordListOptions } from "pocketbase";
|
||||
import { type RecordListOptions, type RecordSubscription } from "pocketbase";
|
||||
|
||||
import { type WorkflowModel } from "@/domain/workflow";
|
||||
import { getPocketBase } from "./pocketbase";
|
||||
@@ -48,3 +48,15 @@ export const save = async (record: MaybeModelRecord<WorkflowModel>) => {
|
||||
export const remove = async (record: MaybeModelRecordWithId<WorkflowModel>) => {
|
||||
return await getPocketBase().collection(COLLECTION_NAME).delete(record.id);
|
||||
};
|
||||
|
||||
export const subscribe = async (id: string, cb: (e: RecordSubscription<WorkflowModel>) => void) => {
|
||||
const pb = getPocketBase();
|
||||
|
||||
return pb.collection("workflow").subscribe(id, cb);
|
||||
};
|
||||
|
||||
export const unsubscribe = async (id: string) => {
|
||||
const pb = getPocketBase();
|
||||
|
||||
return pb.collection("workflow").unsubscribe(id);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user