diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 979b6cd..5158214 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -5,12 +5,19 @@ module.exports = { }, extends: ['plugin:react/recommended', 'standard-with-typescript', 'prettier'], overrides: [], + parser: '@typescript-eslint/parser', parserOptions: { ecmaVersion: 'latest', project: './tsconfig.json', sourceType: 'module', }, - plugins: ['react', 'prettier', 'sort-keys-fix', 'better-styled-components'], + plugins: [ + 'better-styled-components', + 'prettier', + 'react', + 'sort-keys-fix', + 'typescript-sort-keys', + ], rules: { '@typescript-eslint/strict-boolean-expressions': 'off', '@typescript-eslint/triple-slash-reference': 'off', @@ -52,5 +59,7 @@ module.exports = { }, ], 'sort-keys-fix/sort-keys-fix': 'error', + 'typescript-sort-keys/interface': 'error', + 'typescript-sort-keys/string-enum': 'error', }, }; diff --git a/package.json b/package.json index 6843282..0970511 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "zod": "^3.21.4" }, "devDependencies": { - "eslint": "^8.0.1", + "@typescript-eslint/parser": "^5.61.0", + "eslint": "^8.44.0", "eslint-config-prettier": "^8.8.0", "eslint-config-standard-with-typescript": "^34.0.1", "eslint-plugin-better-styled-components": "^1.1.2", @@ -32,6 +33,7 @@ "eslint-plugin-promise": "^6.0.0", "eslint-plugin-react": "^7.32.2", "eslint-plugin-sort-keys-fix": "^1.1.2", + "eslint-plugin-typescript-sort-keys": "^2.3.0", "husky": "^8.0.3", "lerna": "^7.1.1", "lint-staged": "^13.2.0", diff --git a/packages/server/schemas/currency.ts b/packages/server/schemas/currency.ts new file mode 100644 index 0000000..f865921 --- /dev/null +++ b/packages/server/schemas/currency.ts @@ -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); diff --git a/packages/server/schemas/index.ts b/packages/server/schemas/index.ts index e5abc85..5e4ea02 100644 --- a/packages/server/schemas/index.ts +++ b/packages/server/schemas/index.ts @@ -1 +1,4 @@ export * from './user'; +export * from './spending'; +export * from './spendingCategory'; +export * from './currency'; diff --git a/packages/server/schemas/spending.ts b/packages/server/schemas/spending.ts new file mode 100644 index 0000000..c2c856b --- /dev/null +++ b/packages/server/schemas/spending.ts @@ -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); diff --git a/packages/server/schemas/spendingCategory.ts b/packages/server/schemas/spendingCategory.ts new file mode 100644 index 0000000..c61c8ec --- /dev/null +++ b/packages/server/schemas/spendingCategory.ts @@ -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); diff --git a/packages/server/types/currency.ts b/packages/server/types/currency.ts new file mode 100644 index 0000000..2a7b2bc --- /dev/null +++ b/packages/server/types/currency.ts @@ -0,0 +1,5 @@ +import { type StringInput } from './primitives'; + +export interface CurrencyType { + label: StringInput; +} diff --git a/packages/server/types/index.ts b/packages/server/types/index.ts index e5abc85..5e4ea02 100644 --- a/packages/server/types/index.ts +++ b/packages/server/types/index.ts @@ -1 +1,4 @@ export * from './user'; +export * from './spending'; +export * from './spendingCategory'; +export * from './currency'; diff --git a/packages/server/types/primitives.ts b/packages/server/types/primitives.ts index 2535f30..7f2dece 100644 --- a/packages/server/types/primitives.ts +++ b/packages/server/types/primitives.ts @@ -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 }; diff --git a/packages/server/types/spending.ts b/packages/server/types/spending.ts new file mode 100644 index 0000000..d9f78dd --- /dev/null +++ b/packages/server/types/spending.ts @@ -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; +} diff --git a/packages/server/types/spendingCategory.ts b/packages/server/types/spendingCategory.ts new file mode 100644 index 0000000..75f1859 --- /dev/null +++ b/packages/server/types/spendingCategory.ts @@ -0,0 +1,7 @@ +import { type StringInput } from './primitives'; + +export interface SpendingCategoryType { + backgroundColor: StringInput; + label: StringInput; + userId: StringInput; +}