update,
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function deleteCustomer(id) {
|
||||
export async function deleteCustomer(id: string): Promise<boolean> {
|
||||
return pb.collection(COL_CUSTOMERS).delete(id);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getAllCustomers(options = {}) {
|
||||
export async function getAllCustomers(options = {}): Promise<RecordModel[]> {
|
||||
return pb.collection(COL_CUSTOMERS).getFullList(options);
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function getAllCustomersCount() {
|
||||
export async function getAllCustomersCount(): Promise<number> {
|
||||
const result = await pb.collection(COL_CUSTOMERS).getList(1, 1);
|
||||
return result.totalItems;
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getCustomerById(id) {
|
||||
export async function getCustomerById(id: string): Promise<RecordModel> {
|
||||
return pb.collection(COL_CUSTOMERS).getOne(id);
|
||||
}
|
||||
|
@@ -1,9 +0,0 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function getHiddenCustomersCount() {
|
||||
const result = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'hidden = true',
|
||||
});
|
||||
return result.totalItems;
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function getVisibleCustomersCount() {
|
||||
const result = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
filter: 'hidden = false',
|
||||
});
|
||||
return result.totalItems;
|
||||
}
|
@@ -1,8 +1,8 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
import type { CreateForm } from '@/components/dashboard/customer/type.d';
|
||||
import type { EditFormProps } from '@/components/dashboard/customer/type.d';
|
||||
|
||||
export async function updateCustomer(id: string, data: Partial<CustomerUpdateData>): Promise<RecordModel> {
|
||||
export async function updateCustomer(id: string, data: Partial<EditFormProps>): Promise<RecordModel> {
|
||||
return pb.collection(COL_CUSTOMERS).update(id, data);
|
||||
}
|
||||
|
@@ -1,11 +1,12 @@
|
||||
# NOTES
|
||||
# GUIDELINES
|
||||
|
||||
this folder containing driver for `Customer` / `Customers` record:
|
||||
This folder contains drivers for `Customer`/`Customers` records using PocketBase:
|
||||
|
||||
- create (Create.tsx)
|
||||
- read (GetById.tsx)
|
||||
- write (Update.tsx)
|
||||
- count (GetAllCount.tsx, GetHiddenCount.tsx, GetVisibleCount.tsx)
|
||||
- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx)
|
||||
- misc (Helloworld.tsx)
|
||||
- delete (Delete.tsx)
|
||||
- list (GetAll.tsx)
|
||||
|
||||
@@ -15,6 +16,7 @@ the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-onlin
|
||||
|
||||
- assume `pb` is located in `@/lib/pb`
|
||||
- no need to handle error in this function, i'll handle it in the caller
|
||||
- type information defined in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Customers/type.d.tsx`
|
||||
|
||||
simple template:
|
||||
|
||||
@@ -22,7 +24,7 @@ simple template:
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
|
||||
export async function createCustomer(data) {
|
||||
export async function createCustomer(data: CreateFormProps) {
|
||||
// ...content
|
||||
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||
}
|
Reference in New Issue
Block a user