mirror of
https://github.com/FranP-code/spend-ia.git
synced 2025-10-13 00:14:09 +00:00
feat: added models
This commit is contained in:
13
packages/server/schemas/currency.ts
Normal file
13
packages/server/schemas/currency.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { z } from 'zod';
|
||||
import { Schema, model } from 'mongoose';
|
||||
import { type CurrencyType } from '../types';
|
||||
|
||||
export const CurrencySchema = z.object({
|
||||
label: z.string(),
|
||||
} satisfies CurrencyType);
|
||||
|
||||
const schema = new Schema({
|
||||
label: { required: true, type: String },
|
||||
} satisfies CurrencyType);
|
||||
|
||||
export const Currency = model('Currency', schema);
|
||||
@@ -1 +1,4 @@
|
||||
export * from './user';
|
||||
export * from './spending';
|
||||
export * from './spendingCategory';
|
||||
export * from './currency';
|
||||
|
||||
21
packages/server/schemas/spending.ts
Normal file
21
packages/server/schemas/spending.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { z } from 'zod';
|
||||
import { Schema, model } from 'mongoose';
|
||||
import { type SpendingType } from '../types/spending';
|
||||
|
||||
export const SpendingSchema = z.object({
|
||||
amount: z.number(),
|
||||
currencyId: z.string(),
|
||||
date: z.date(),
|
||||
spendingCategoryId: z.string(),
|
||||
userId: z.string(),
|
||||
} satisfies SpendingType);
|
||||
|
||||
const schema = new Schema({
|
||||
amount: { required: true, type: Number },
|
||||
currencyId: { required: true, type: String },
|
||||
date: { required: true, type: Date },
|
||||
spendingCategoryId: { required: true, type: String },
|
||||
userId: { required: true, type: String },
|
||||
} satisfies SpendingType);
|
||||
|
||||
export const Spending = model('Spending', schema);
|
||||
17
packages/server/schemas/spendingCategory.ts
Normal file
17
packages/server/schemas/spendingCategory.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { z } from 'zod';
|
||||
import { Schema, model } from 'mongoose';
|
||||
import { type SpendingCategoryType } from '../types';
|
||||
|
||||
export const SpendingCategorySchema = z.object({
|
||||
backgroundColor: z.string(),
|
||||
label: z.string(),
|
||||
userId: z.string(),
|
||||
} satisfies SpendingCategoryType);
|
||||
|
||||
const schema = new Schema({
|
||||
backgroundColor: { required: true, type: String },
|
||||
label: { required: true, type: String },
|
||||
userId: { required: true, type: String },
|
||||
} satisfies SpendingCategoryType);
|
||||
|
||||
export const SpendingCategory = model('SpendingCategory', schema);
|
||||
5
packages/server/types/currency.ts
Normal file
5
packages/server/types/currency.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { type StringInput } from './primitives';
|
||||
|
||||
export interface CurrencyType {
|
||||
label: StringInput;
|
||||
}
|
||||
@@ -1 +1,4 @@
|
||||
export * from './user';
|
||||
export * from './spending';
|
||||
export * from './spendingCategory';
|
||||
export * from './currency';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { type z } from 'zod';
|
||||
|
||||
export type StringInput = string | z.ZodString | { type: StringConstructor; [key: string]: any };
|
||||
export type StringInput = string | z.ZodString | { [key: string]: any; type: StringConstructor };
|
||||
export type NumberInput = number | z.ZodNumber | { [key: string]: any; type: NumberConstructor };
|
||||
export type DateInput = Date | z.ZodDate | { [key: string]: any; type: DateConstructor };
|
||||
|
||||
9
packages/server/types/spending.ts
Normal file
9
packages/server/types/spending.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { type StringInput, type DateInput, type NumberInput } from './primitives';
|
||||
|
||||
export interface SpendingType {
|
||||
amount: NumberInput;
|
||||
currencyId: StringInput;
|
||||
date: DateInput;
|
||||
spendingCategoryId: StringInput;
|
||||
userId: StringInput;
|
||||
}
|
||||
7
packages/server/types/spendingCategory.ts
Normal file
7
packages/server/types/spendingCategory.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { type StringInput } from './primitives';
|
||||
|
||||
export interface SpendingCategoryType {
|
||||
backgroundColor: StringInput;
|
||||
label: StringInput;
|
||||
userId: StringInput;
|
||||
}
|
||||
Reference in New Issue
Block a user