``add new database operations for billing address module including create, delete, get, update functions and related type definitions
``
This commit is contained in:
11
002_source/cms/src/db/billingAddress/Create.tsx
Normal file
11
002_source/cms/src/db/billingAddress/Create.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// api method for crate student record
|
||||||
|
// RULES:
|
||||||
|
// TBA
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_STUDENTS } from '@/constants';
|
||||||
|
import type { CreateFormProps } from '@/components/dashboard/student/type.d';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
export async function createStudent(data: CreateFormProps): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_STUDENTS).create(data);
|
||||||
|
}
|
6
002_source/cms/src/db/billingAddress/Delete.tsx
Normal file
6
002_source/cms/src/db/billingAddress/Delete.tsx
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_STUDENTS, COL_USER_METAS } from '@/constants';
|
||||||
|
|
||||||
|
export async function deleteStudent(id: string): Promise<boolean> {
|
||||||
|
return pb.collection(COL_USER_METAS).delete(id);
|
||||||
|
}
|
9
002_source/cms/src/db/billingAddress/GetActiveCount.tsx
Normal file
9
002_source/cms/src/db/billingAddress/GetActiveCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { COL_STUDENTS, COL_USER_METAS } from '@/constants';
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
export default async function GetActiveCount(): Promise<number> {
|
||||||
|
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||||
|
filter: 'status = "active" && role = "student"',
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
7
002_source/cms/src/db/billingAddress/GetAll.tsx
Normal file
7
002_source/cms/src/db/billingAddress/GetAll.tsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_STUDENTS } from '@/constants';
|
||||||
|
import { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
export async function getAllStudents(options = {}): Promise<RecordModel[]> {
|
||||||
|
return pb.collection(COL_STUDENTS).getFullList(options);
|
||||||
|
}
|
10
002_source/cms/src/db/billingAddress/GetAllCount.tsx
Normal file
10
002_source/cms/src/db/billingAddress/GetAllCount.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
|
||||||
|
export async function getAllStudentsCount(): Promise<number> {
|
||||||
|
const result = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||||
|
filter: `role = "student"`,
|
||||||
|
//
|
||||||
|
});
|
||||||
|
return result.totalItems;
|
||||||
|
}
|
9
002_source/cms/src/db/billingAddress/GetBlockedCount.tsx
Normal file
9
002_source/cms/src/db/billingAddress/GetBlockedCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
export default async function GetBlockedCount(): Promise<number> {
|
||||||
|
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||||
|
filter: 'status = "blocked" && role = "student"',
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
34
002_source/cms/src/db/billingAddress/GetById.tsx
Normal file
34
002_source/cms/src/db/billingAddress/GetById.tsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { COL_BILLING_ADDRESS, COL_STUDENTS, COL_USER_METAS } from '@/constants';
|
||||||
|
import { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { logger } from '@/lib/default-logger';
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type.d';
|
||||||
|
|
||||||
|
export async function getBillingAddressById(id: string): Promise<UserMeta> {
|
||||||
|
const record = await pb
|
||||||
|
.collection(COL_BILLING_ADDRESS)
|
||||||
|
.getOne<DBUserMeta>(id, { expand: 'billingAddress, helloworld' });
|
||||||
|
|
||||||
|
console.log({ record });
|
||||||
|
|
||||||
|
const temp: UserMeta = {
|
||||||
|
id: record.id,
|
||||||
|
name: record.name,
|
||||||
|
email: record.email,
|
||||||
|
quota: record.quota,
|
||||||
|
billingAddress: record.expand.billingAddress ? record.expand.billingAddress[0] : {},
|
||||||
|
status: record.status,
|
||||||
|
state: record.state,
|
||||||
|
createdAt: new Date(record.created),
|
||||||
|
collectionId: record.collectionId,
|
||||||
|
avatar: record.avatar,
|
||||||
|
phone: record.phone,
|
||||||
|
company: record.company,
|
||||||
|
timezone: record.timezone,
|
||||||
|
language: record.language,
|
||||||
|
currency: record.currency,
|
||||||
|
};
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
9
002_source/cms/src/db/billingAddress/GetPendingCount.tsx
Normal file
9
002_source/cms/src/db/billingAddress/GetPendingCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
export default async function GetPendingCount(): Promise<number> {
|
||||||
|
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||||
|
filter: 'status = "pending" && role = "student"',
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
3
002_source/cms/src/db/billingAddress/Helloworld.tsx
Normal file
3
002_source/cms/src/db/billingAddress/Helloworld.tsx
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function helloCustomer() {
|
||||||
|
return 'Hello from Customers module!';
|
||||||
|
}
|
8
002_source/cms/src/db/billingAddress/Update.tsx
Normal file
8
002_source/cms/src/db/billingAddress/Update.tsx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_CUSTOMERS } from '@/constants';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
import type { EditFormProps } from '@/components/dashboard/customer/type.d';
|
||||||
|
|
||||||
|
export async function updateCustomer(id: string, data: Partial<EditFormProps>): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_CUSTOMERS).update(id, data);
|
||||||
|
}
|
10
002_source/cms/src/db/billingAddress/UpdateById.tsx
Normal file
10
002_source/cms/src/db/billingAddress/UpdateById.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { COL_BILLING_ADDRESS } from '@/constants';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
import type { UpdateBillingAddress } from './type';
|
||||||
|
|
||||||
|
export async function UpdateBillingAddressById(id: string, data: Partial<UpdateBillingAddress>): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_BILLING_ADDRESS).update(id, data);
|
||||||
|
}
|
31
002_source/cms/src/db/billingAddress/_GUIDELINES.md
Normal file
31
002_source/cms/src/db/billingAddress/_GUIDELINES.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# GUIDELINES
|
||||||
|
|
||||||
|
This folder contains drivers for `Customer`/`Customers` records using PocketBase:
|
||||||
|
|
||||||
|
- create (Create.tsx)
|
||||||
|
- read (GetById.tsx)
|
||||||
|
- write (Update.tsx)
|
||||||
|
- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx)
|
||||||
|
- misc (Helloworld.tsx)
|
||||||
|
- delete (Delete.tsx)
|
||||||
|
- list (GetAll.tsx)
|
||||||
|
|
||||||
|
the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src`
|
||||||
|
|
||||||
|
## Assumption and Requirements
|
||||||
|
|
||||||
|
- 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:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_CUSTOMERS } from '@/constants';
|
||||||
|
|
||||||
|
export async function createCustomer(data: CreateFormProps) {
|
||||||
|
// ...content
|
||||||
|
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||||
|
}
|
||||||
|
```
|
23
002_source/cms/src/db/billingAddress/type.d.ts
vendored
Normal file
23
002_source/cms/src/db/billingAddress/type.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
export interface BillingAddress {
|
||||||
|
city: string;
|
||||||
|
country: string;
|
||||||
|
line1: string;
|
||||||
|
line2: string;
|
||||||
|
state: string;
|
||||||
|
zipCode: string;
|
||||||
|
//
|
||||||
|
id: string;
|
||||||
|
collectionId: string;
|
||||||
|
collectionName: string;
|
||||||
|
updated: string;
|
||||||
|
created: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateBillingAddress {
|
||||||
|
city?: string;
|
||||||
|
country?: string;
|
||||||
|
line1?: string;
|
||||||
|
line2?: string;
|
||||||
|
state?: string;
|
||||||
|
zipCode?: string;
|
||||||
|
}
|
Reference in New Issue
Block a user