Skip to content

Commit a73d332

Browse files
committed
feat: add product status
1 parent b052b5e commit a73d332

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thecodeorigin/nuxt",
33
"type": "module",
4-
"version": "2.4.6",
4+
"version": "2.4.7",
55
"publishConfig": {
66
"registry": "https://registry.npmjs.org",
77
"access": "public"

server/composables/useCredit.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import type { CreditHistoryType } from '@base/server/db/schemas'
2-
import { creditHistoryTable } from '@base/server/db/schemas'
2+
import { ProductStatus, creditHistoryTable } from '@base/server/db/schemas'
33
import type { CreditHistory, Product } from '@base/server/types/models'
44

55
export function useCredit() {
66
function getProducts(): Promise<Product[]> {
77
return db.query.productTable.findMany({
8+
where(schema, { eq }) {
9+
return eq(schema.status, ProductStatus.ACTIVE)
10+
},
811
orderBy(fields, { asc }) {
912
return asc(fields.price)
1013
},

server/composables/useProduct.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import type { Product } from '@base/server/types/models'
2-
import { ProductType } from '../db/schemas'
2+
import { ProductStatus, ProductType } from '../db/schemas'
33

44
export function useProduct() {
55
function getProducts(): Promise<Product[]> {
66
return db.query.productTable.findMany({
7+
where(schema, { eq }) {
8+
return eq(schema.status, ProductStatus.ACTIVE)
9+
},
710
orderBy(schema, { asc }) {
811
return [
912
asc(schema.position),
@@ -14,8 +17,11 @@ export function useProduct() {
1417

1518
function getCreditPackages(): Promise<Product[]> {
1619
return db.query.productTable.findMany({
17-
where(schema, { eq }) {
18-
return eq(schema.type, ProductType.CREDIT)
20+
where(schema, { eq, and }) {
21+
return and(
22+
eq(schema.type, ProductType.CREDIT),
23+
eq(schema.status, ProductStatus.ACTIVE),
24+
)
1925
},
2026
orderBy(schema, { asc }) {
2127
return [
@@ -27,8 +33,11 @@ export function useProduct() {
2733

2834
function getProductByProductId(productId: string): Promise<Pick<Product, 'id' | 'price' | 'amount'> | undefined> {
2935
return db.query.productTable.findFirst({
30-
where(schema, { eq }) {
31-
return eq(schema.id, productId)
36+
where(schema, { eq, and }) {
37+
return and(
38+
eq(schema.id, productId),
39+
eq(schema.status, ProductStatus.ACTIVE),
40+
)
3241
},
3342
columns: {
3443
id: true,

server/db/schemas/enum.schema.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@ export enum ProductType {
2727
OTHER = 'other',
2828
}
2929

30+
export enum ProductStatus {
31+
ACTIVE = 'active',
32+
INACTIVE = 'inactive',
33+
}
34+
3035
export const paymentStatus = pgEnum('payment_status', enumToPgEnum(PaymentStatus))
3136

3237
export const creditHistoryType = pgEnum('credit_history_type', enumToPgEnum(CreditHistoryType))
3338

3439
export const supportedCurrency = pgEnum('supported_currency', enumToPgEnum(SupportedCurrency))
3540

3641
export const productType = pgEnum('product_type', enumToPgEnum(ProductType))
42+
43+
export const productStatus = pgEnum('product_status', enumToPgEnum(ProductStatus))

server/db/schemas/products.schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { jsonb, numeric, pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core'
22
import { relations } from 'drizzle-orm/relations'
33
import { orderTable } from './orders.schema'
4-
import { ProductType, productType } from './enum.schema'
4+
import { ProductType, productStatus, productType } from './enum.schema'
55

66
interface PricingPlanFeature {
77
title: string
@@ -19,6 +19,7 @@ export const productTable = pgTable('products', {
1919
type: productType('type').default(ProductType.CREDIT).notNull(),
2020
features: jsonb('features').$type<string[] | PricingPlanFeature[]>().default([]),
2121
position: numeric('position'),
22+
status: productStatus('status').default('active').notNull(),
2223
created_at: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
2324
updated_at: timestamp('updated_at', { withTimezone: true }).defaultNow().$onUpdate(() => new Date()),
2425
})

0 commit comments

Comments
 (0)