& so it begins
This commit is contained in:
102
packages/logic/domains/notifications/data.ts
Normal file
102
packages/logic/domains/notifications/data.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import * as v from "valibot";
|
||||
|
||||
// Notification schema
|
||||
export const notificationSchema = v.object({
|
||||
id: v.pipe(v.number(), v.integer()),
|
||||
title: v.string(),
|
||||
body: v.string(),
|
||||
priority: v.string(),
|
||||
type: v.string(),
|
||||
category: v.string(),
|
||||
isRead: v.boolean(),
|
||||
isArchived: v.boolean(),
|
||||
actionUrl: v.string(),
|
||||
actionType: v.string(),
|
||||
actionData: v.string(),
|
||||
icon: v.string(),
|
||||
userId: v.string(),
|
||||
sentAt: v.date(),
|
||||
readAt: v.nullable(v.date()),
|
||||
expiresAt: v.nullable(v.date()),
|
||||
createdAt: v.date(),
|
||||
updatedAt: v.date(),
|
||||
});
|
||||
|
||||
export type Notification = v.InferOutput<typeof notificationSchema>;
|
||||
export type Notifications = Notification[];
|
||||
|
||||
// Notification filters schema
|
||||
export const notificationFiltersSchema = v.object({
|
||||
userId: v.string(),
|
||||
isRead: v.optional(v.boolean()),
|
||||
isArchived: v.optional(v.boolean()),
|
||||
type: v.optional(v.string()),
|
||||
category: v.optional(v.string()),
|
||||
priority: v.optional(v.string()),
|
||||
search: v.optional(v.string()),
|
||||
});
|
||||
export type NotificationFilters = v.InferOutput<
|
||||
typeof notificationFiltersSchema
|
||||
>;
|
||||
|
||||
// Pagination options schema
|
||||
export const paginationOptionsSchema = v.object({
|
||||
page: v.pipe(v.number(), v.integer()),
|
||||
pageSize: v.pipe(v.number(), v.integer()),
|
||||
sortBy: v.optional(v.string()),
|
||||
sortOrder: v.optional(v.string()),
|
||||
});
|
||||
export type PaginationOptions = v.InferOutput<typeof paginationOptionsSchema>;
|
||||
|
||||
// Paginated notifications schema
|
||||
export const paginatedNotificationsSchema = v.object({
|
||||
data: v.array(notificationSchema),
|
||||
total: v.pipe(v.number(), v.integer()),
|
||||
page: v.pipe(v.number(), v.integer()),
|
||||
pageSize: v.pipe(v.number(), v.integer()),
|
||||
totalPages: v.pipe(v.number(), v.integer()),
|
||||
});
|
||||
export type PaginatedNotifications = v.InferOutput<
|
||||
typeof paginatedNotificationsSchema
|
||||
>;
|
||||
|
||||
// Get notifications schema
|
||||
export const getNotificationsSchema = v.object({
|
||||
filters: notificationFiltersSchema,
|
||||
pagination: paginationOptionsSchema,
|
||||
});
|
||||
export type GetNotifications = v.InferOutput<typeof getNotificationsSchema>;
|
||||
|
||||
// Bulk notification IDs schema
|
||||
export const bulkNotificationIdsSchema = v.object({
|
||||
notificationIds: v.array(v.pipe(v.number(), v.integer())),
|
||||
});
|
||||
export type BulkNotificationIds = v.InferOutput<
|
||||
typeof bulkNotificationIdsSchema
|
||||
>;
|
||||
|
||||
// View Model specific types
|
||||
export const clientNotificationFiltersSchema = v.object({
|
||||
userId: v.string(),
|
||||
isRead: v.optional(v.boolean()),
|
||||
isArchived: v.optional(v.boolean()),
|
||||
type: v.optional(v.string()),
|
||||
category: v.optional(v.string()),
|
||||
priority: v.optional(v.string()),
|
||||
search: v.optional(v.string()),
|
||||
});
|
||||
export type ClientNotificationFilters = v.InferOutput<
|
||||
typeof clientNotificationFiltersSchema
|
||||
>;
|
||||
|
||||
export const clientPaginationStateSchema = v.object({
|
||||
page: v.pipe(v.number(), v.integer()),
|
||||
pageSize: v.pipe(v.number(), v.integer()),
|
||||
total: v.pipe(v.number(), v.integer()),
|
||||
totalPages: v.pipe(v.number(), v.integer()),
|
||||
sortBy: v.picklist(["createdAt", "sentAt", "readAt", "priority"]),
|
||||
sortOrder: v.picklist(["asc", "desc"]),
|
||||
});
|
||||
export type ClientPaginationState = v.InferOutput<
|
||||
typeof clientPaginationStateSchema
|
||||
>;
|
||||
Reference in New Issue
Block a user