-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new collection coupon, add url to partner and coupon router
- Loading branch information
Showing
8 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { type CollectionConfig } from "payload/types"; | ||
|
||
export const Coupons: CollectionConfig = { | ||
slug: "coupons", | ||
labels: { | ||
singular: "Bon de réduction", | ||
plural: "Bons de réduction", | ||
}, | ||
fields: [ | ||
{ | ||
name: "code", | ||
type: "text", | ||
label: "Code", | ||
required: true, | ||
unique: true, | ||
}, | ||
{ | ||
name: "status", | ||
type: "select", | ||
label: "Statut", | ||
options: [ | ||
{ label: "Disponible", value: "available" }, | ||
{ label: "Archivé", value: "archived" }, | ||
], | ||
defaultValue: "available", | ||
required: true, | ||
}, | ||
{ | ||
name: "validityTo", | ||
type: "date", | ||
label: "Validité jusqu'au", | ||
required: true, | ||
}, | ||
{ | ||
name: "user", | ||
type: "relationship", | ||
label: "Utilisateur", | ||
relationTo: "users", | ||
hasMany: false, | ||
}, | ||
{ | ||
name: "offer", | ||
type: "relationship", | ||
label: "Offre", | ||
relationTo: "offers", | ||
hasMany: false, | ||
required: true, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { z } from "zod"; | ||
import { Coupon, Media, Offer, User } from "~/payload/payload-types"; | ||
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc"; | ||
|
||
interface CouponIncluded extends Coupon { | ||
offer: Offer & { icon: Media }; | ||
userRouter: User; | ||
} | ||
|
||
export const couponRouter = createTRPCRouter({ | ||
getOneAvailable: protectedProcedure | ||
.input(z.object({ offer_id: z.number() })) | ||
.query(async ({ ctx, input }) => { | ||
const { offer_id } = input; | ||
|
||
const coupons = await ctx.payload.find({ | ||
collection: "coupons", | ||
where: { | ||
and: [ | ||
{ offer: { equals: offer_id } }, | ||
{ status: { equals: "available" } }, | ||
{ validityTo: { greater_than_equal: new Date() } }, | ||
], | ||
}, | ||
}); | ||
|
||
return { data: coupons.docs[0] as CouponIncluded }; | ||
}), | ||
}); |