WIP: feat: add zod schemas #2093

Draft
konrad wants to merge 4 commits from feature/zod-schema into main
66 changed files with 1009 additions and 230 deletions

View File

@ -5,7 +5,7 @@ body:
- type: markdown
attributes:
value: |
NOTE: If your issue is a security concern, please send an email to security@vikunja.io instead of opening a public issue.
NOTE: If your issue is a security concern, please send an email to security@vikunja.io instead of opening a public issue. [More information about our security policy](https://vikunja.io/contact/#security).
- type: markdown
attributes:
value: |
@ -24,17 +24,10 @@ body:
description: |
Please provide a description of your issue here, with a URL if you were able to reproduce the issue (see below).
- type: input
id: frontend-version
id: version
attributes:
label: Vikunja Frontend Version
description: Vikunja frontend version (or commit reference) of your instance
validations:
required: true
- type: input
id: api-version
attributes:
label: Vikunja API Version
description: Vikunja API version (or commit reference) of your instance
label: Vikunja Version
description: Vikunja version (or commit reference) of your instance
validations:
required: true
- type: input
@ -47,6 +40,7 @@ body:
attributes:
label: Can you reproduce the bug on the Vikunja demo site?
options:
- "Please select"
- "Yes"
- "No"
validations:

View File

@ -1,8 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Frontend issues
url: https://code.vikunja.io/frontend/issues
about: This is the API repo. Please open frontend-related bug reports and discussions in the frontend repo. Not sure if you issue is frontend or api? Ask in Matrix or the forum first.
- name: Forum
url: https://community.vikunja.io/
about: Feature Requests, Questions, configuration or deployment problems should be discussed in the forum.

View File

@ -16,7 +16,7 @@ jobs:
with:
pr-comment: 'Hi! Thank you for your contribution.
This repo is only a mirror and unfortunately we can''t accept PRs made here. Please re-submit your changes to [our Gitea instance](https://kolaente.dev/vikunja/api/pulls).
This repo is only a mirror and unfortunately we can''t accept PRs made here. Please re-submit your changes to [our Gitea instance](https://kolaente.dev/vikunja/vikunja/pulls).
Also check out the [contribution guidelines](https://vikunja.io/docs/development/#pull-requests).

34
.vscode/settings.json vendored
View File

@ -1,5 +1,37 @@
{
"go.testEnvVars": {
"VIKUNJA_SERVICE_ROOTPATH": "${workspaceRoot}"
}
},
"eslint.packageManager": "pnpm",
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"eslint.format.enable": true,
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
// https://eslint.vuejs.org/user-guide/#editor-integrations
"eslint.validate": [
"javascript",
"javascriptreact",
"vue"
],
"volar.completion.preferredTagNameCase": "pascal",
// disable vetur in case it is installed
"vetur.validation.template": false,
// i18n ally
"i18n-ally.localesPaths": [
"src/i18n/lang"
],
"i18n-ally.sortKeys": true,
"i18n-ally.keepFulfilled": true,
"i18n-ally.keystyle": "nested"
}

View File

@ -1,11 +1,11 @@
<img src="https://vikunja.io/images/vikunja-logo.svg" alt="" style="display: block;width: 50%;margin: 0 auto;" width="50%"/>
[![Build Status](https://drone.kolaente.de/api/badges/vikunja/api/status.svg)](https://drone.kolaente.de/vikunja/api)
[![Build Status](https://drone.kolaente.de/api/badges/vikunja/vikunjaa/status.svg)](https://drone.kolaente.de/vikunja/vikunja)
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](LICENSE)
[![Download](https://img.shields.io/badge/download-v0.22.1-brightgreen.svg)](https://dl.vikunja.io)
[![Docker Pulls](https://img.shields.io/docker/pulls/vikunja/api.svg)](https://hub.docker.com/r/vikunja/api/)
[![Docker Pulls](https://img.shields.io/docker/pulls/vikunja/vikunja.svg)](https://hub.docker.com/r/vikunja/vikunja/)
[![Swagger Docs](https://img.shields.io/badge/swagger-docs-brightgreen.svg)](https://try.vikunja.io/api/v1/docs)
[![Go Report Card](https://goreportcard.com/badge/kolaente.dev/vikunja/api)](https://goreportcard.com/report/kolaente.dev/vikunja/api)
[![Go Report Card](https://goreportcard.com/badge/kolaente.dev/vikunja/vikunja)](https://goreportcard.com/report/kolaente.dev/vikunja/vikunja)
# Vikunja API

View File

@ -296,7 +296,7 @@ auth:
# auth service accordingly if you're using the default vikunja frontend.
# The frontend will automatically provide the api with the redirect url, composed from the current url where it's hosted.
# If you want to use the desktop client with openid, make sure to allow redirects to `127.0.0.1`.
# Take a look at the [default config file](https://kolaente.dev/vikunja/api/src/branch/main/config.yml.sample) for more information about how to configure openid authentication.
# Take a look at the [default config file](https://kolaente.dev/vikunja/vikunja/src/branch/main/config.yml.sample) for more information about how to configure openid authentication.
openid:
# Enable or disable OpenID Connect authentication
enabled: false
@ -343,7 +343,7 @@ defaultsettings:
default_project_id: 0
# Start of the week for the user. `0` is sunday, `1` is monday and so on.
week_start: 0
# The language of the user interface. Must be an ISO 639-1 language code followed by an ISO 3166-1 alpha-2 country code. Check https://kolaente.dev/vikunja/frontend/src/branch/main/src/i18n/lang for a list of possible languages. Will default to the browser language the user uses when signing up.
# The language of the user interface. Must be an ISO 639-1 language code followed by an ISO 3166-1 alpha-2 country code. Check https://kolaente.dev/vikunja/vikunja/frontend/src/branch/main/src/i18n/lang for a list of possible languages. Will default to the browser language the user uses when signing up.
language: <unset>
# The time zone of each individual user. This will affect when users get reminders and overdue task emails.
timezone: <time zone set at service.timezone>

View File

@ -91,7 +91,7 @@ fixtures other than db fixtures (like files).
## Frontend tests
The frontend has end to end tests with Cypress that use a Vikunja instance and drive a browser against it.
Check out the docs [in the frontend repo](https://kolaente.dev/vikunja/frontend/src/branch/main/cypress/README.md) about how they work and how to get them running.
Check out the docs [in the frontend repo](https://kolaente.dev/vikunja/vikunja/src/branch/main/frontend/cypress/README.md) about how they work and how to get them running.
### Unit Tests

View File

@ -32,7 +32,7 @@ first:
Vikunja supports using `toml`, `yaml`, `hcl`, `ini`, `json`, envfile, env variables and Java Properties files.
We recommend yaml or toml, but you're free to use whatever you want.
Vikunja provides a default [`config.yml`](https://kolaente.dev/vikunja/api/src/branch/main/config.yml.sample) file which you can use as a starting point.
Vikunja provides a default [`config.yml`](https://kolaente.dev/vikunja/vikunja/src/branch/main/config.yml.sample) file which you can use as a starting point.
# Config file locations
@ -1161,7 +1161,7 @@ If the email is not public in those cases, authenticating will fail.
**Note 2:** The frontend expects to be redirected after authentication by the third party
to <frontend-url>/auth/openid/<auth key>. Please make sure to configure the redirect url with your third party
auth service accordingly if you're using the default vikunja frontend.
Take a look at the [default config file](https://kolaente.dev/vikunja/api/src/branch/main/config.yml.sample) for more information about how to configure openid authentication.
Take a look at the [default config file](https://kolaente.dev/vikunja/vikunja/src/branch/main/config.yml.sample) for more information about how to configure openid authentication.
Default: `<empty>`
@ -1320,7 +1320,7 @@ Environment path: `VIKUNJA_DEFAULTSETTINGS_WEEK_START`
### language
The language of the user interface. Must be an ISO 639-1 language code followed by an ISO 3166-1 alpha-2 country code. Check https://kolaente.dev/vikunja/frontend/src/branch/main/src/i18n/lang for a list of possible languages. Will default to the browser language the user uses when signing up.
The language of the user interface. Must be an ISO 639-1 language code followed by an ISO 3166-1 alpha-2 country code. Check https://kolaente.dev/vikunja/vikunja/src/branch/main/frontend/src/i18n/lang for a list of possible languages. Will default to the browser language the user uses when signing up.
Default: `<unset>`

View File

@ -11,7 +11,7 @@ menu:
# OpenID example configurations
On this page you will find examples about how to set up Vikunja with a third-party OpenID provider.
To add another example, please [edit this document](https://kolaente.dev/vikunja/api/src/branch/main/docs/content/doc/setup/openid-examples.md) and send a PR.
To add another example, please [edit this document](https://kolaente.dev/vikunja/vikunja/src/branch/main/docs/content/doc/setup/openid-examples.md) and send a PR.
{{< table_of_contents >}}

View File

@ -76,7 +76,7 @@ Vikunja **currently does not** support these properties:
### Not working
* [Thunderbird (68)](https://www.thunderbird.net/)
* iOS CalDAV Sync (See [#753](https://kolaente.dev/vikunja/api/issues/753))
* iOS CalDAV Sync (See [#753](https://kolaente.dev/vikunja/vikunja/issues/753))
## Dev logs

View File

@ -22,7 +22,7 @@ Check out [the api docs](https://try.vikunja.io/api/v1/docs#tag/webhooks) for in
## Available events and their payload
All events registered as webhook events in [the event listeners definition](https://kolaente.dev/vikunja/api/src/branch/main/pkg/models/listeners.go#L69) can be used as webhook target.
All events registered as webhook events in [the event listeners definition](https://kolaente.dev/vikunja/vikunja/src/branch/main/pkg/models/listeners.go#L69) can be used as webhook target.
A webhook payload will look similar to this:

View File

@ -1,44 +0,0 @@
<!--
Please fill out this issue template to report a bug.
If you want to propose a new feature, please open a discussion thread in the forum: https://community.vikunja.io
-->
**Version information:**
Frontend Version:
API Version:
Browser and OS Version:
**Steps to reproduce:**
<!--
Add clear steps to reproduce the bug. Provide screenshots where applicable.
-->
1.
2.
...
**Expected behavior:**
<!--
Describe what happened.
-->
**Actual behavior:**
<!--
Describe what happened instead.
-->
**Checklist:**
* [ ] I have provided all required information
* [ ] I am using the latest release or the latest unstable build
* [ ] I was able to reproduce the bug on [try](https://try.vikunja.io)

View File

@ -1,3 +0,0 @@
github: kolaente
open_collective: vikunja
custom: ["https://vikunja.cloud", "https://www.buymeacoffee.com/kolaente"]

View File

@ -1,59 +0,0 @@
name: Bug Report
description: Found something you weren't expecting? Report it here!
labels:
- kind/bug
body:
- type: markdown
attributes:
value: |
NOTE: If your issue is a security concern, please send an email to security@vikunja.io instead of opening a public issue.
- type: markdown
attributes:
value: |
Please fill out this issue template to report a bug.
1. If you want to propose a new feature, please open a discussion thread in the forum: https://community.vikunja.io
2. Please ask questions or configuration/deploy problems on our [Matrix Room](https://matrix.to/#/#vikunja:matrix.org) or forum (https://community.vikunja.io).
3. Make sure you are using the latest release and
take a moment to check that your issue hasn't been reported before.
4. Please give all relevant information below for bug reports, because
incomplete details will be handled as an invalid report and closed.
- type: textarea
id: description
attributes:
label: Description
description: |
Please provide a description of your issue here, with a URL if you were able to reproduce the issue (see below).
- type: input
id: frontend-version
attributes:
label: Vikunja Frontend Version
description: Vikunja frontend version (or commit reference) of your instance
validations:
required: true
- type: input
id: api-version
attributes:
label: Vikunja API Version
description: Vikunja API version (or commit reference) of your instance
validations:
required: true
- type: input
id: browser-version
attributes:
label: Browser and version
description: If your issue is related to a frontend problem, please provide the browser and version you used to reproduce it.
- type: dropdown
id: can-reproduce
attributes:
label: Can you reproduce the bug on the Vikunja demo site?
options:
- "Yes"
- "No"
validations:
required: true
- type: textarea
id: screenshots
attributes:
label: Screenshots
description: If this issue involves the Web Interface, please provide one or more screenshots

View File

@ -1,17 +0,0 @@
blank_issues_enabled: false
contact_links:
- name: API issues
url: https://code.vikunja.io/api/issues
about: This is the frontend repo. Please open api-related bug reports and discussions in the api 0repo. Not sure if your issue is frontend or api? Ask in Matrix or the forum first.
- name: Forum
url: https://community.vikunja.io/
about: Feature Requests, Questions, configuration or deployment problems should be discussed in the forum.
- name: Security-related issues
url: https://vikunja.io/contact/#security
about: For security concerns, please send a mail to security@vikunja.io instead of opening a public issue.
- name: Chat on Matrix
url: https://matrix.to/#/#vikunja:matrix.org
about: Please ask any quick questions here.
- name: Translations
url: https://crowdin.com/project/vikunja
about: Any problems or requests for new languages about translations should be handled in crowdin.

View File

@ -1,23 +0,0 @@
name: 'Repo Lockdown'
on:
pull_request_target:
types: opened
permissions:
issues: write
pull-requests: write
jobs:
action:
runs-on: ubuntu-latest
steps:
- uses: dessant/repo-lockdown@v4
with:
pr-comment: 'Hi! Thank you for your contribution.
This repo is only a mirror and unfortunately we can''t accept PRs made here. Please re-submit your changes to [our Gitea instance](https://kolaente.dev/vikunja/frontend/pulls).
Also check out the [contribution guidelines](https://vikunja.io/docs/development/#pull-requests).
Thank you for your understanding.'

View File

@ -1,34 +0,0 @@
{
"eslint.packageManager": "pnpm",
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"eslint.format.enable": true,
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
// https://eslint.vuejs.org/user-guide/#editor-integrations
"eslint.validate": [
"javascript",
"javascriptreact",
"vue"
],
"volar.completion.preferredTagNameCase": "pascal",
// disable vetur in case it is installed
"vetur.validation.template": false,
// i18n ally
"i18n-ally.localesPaths": [
"src/i18n/lang"
],
"i18n-ally.sortKeys": true,
"i18n-ally.keepFulfilled": true,
"i18n-ally.keystyle": "nested"
}

View File

@ -2,7 +2,7 @@
> The todo app to organize your life.
[![Build Status](https://drone.kolaente.de/api/badges/vikunja/frontend/status.svg)](https://drone.kolaente.de/vikunja/frontend)
[![Build Status](https://drone.kolaente.de/api/badges/vikunja/vikunja/status.svg)](https://drone.kolaente.de/vikunja/vikunja)
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](LICENSE)
[![Download](https://img.shields.io/badge/download-v0.22.1-brightgreen.svg)](https://dl.vikunja.io)
[![Translation](https://badges.crowdin.net/vikunja/localized.svg)](https://crowdin.com/project/vikunja)
@ -17,7 +17,7 @@ If you find any security-related issues you don't want to disclose publicly, ple
## Docker
There is a [docker image available](https://hub.docker.com/r/vikunja/api) with support for http/2 and aggressive caching enabled.
There is a [docker image available](https://hub.docker.com/r/vikunja/vikunja) with support for http/2 and aggressive caching enabled.
In order to build it from sources run the command below. (Docker >= v19.03)
```shell

View File

@ -6,10 +6,10 @@
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
"url": "https://kolaente.dev/vikunja/frontend"
"url": "https://kolaente.dev/vikunja/vikunja"
},
"bugs": {
"url": "https://kolaente.dev/vikunja/frontend/issues"
"url": "https://kolaente.dev/vikunja/vikunja/issues"
},
"homepage": "https://vikunja.io/",
"funding": "https://opencollective.com/vikunja",
@ -115,13 +115,15 @@
"sortablejs": "1.15.2",
"tippy.js": "6.3.7",
"ufo": "1.4.0",
"validator": "13.9.0",
"vue": "3.4.15",
"vue-advanced-cropper": "2.8.8",
"vue-flatpickr-component": "11.0.3",
"vue-i18n": "9.9.1",
"vue-router": "4.2.5",
"workbox-precaching": "7.0.0",
"zhyswan-vuedraggable": "4.1.3"
"zhyswan-vuedraggable": "4.1.3",
"zod": "3.20.6"
},
"devDependencies": {
"@4tw/cypress-drag-drop": "2.2.5",
@ -141,6 +143,7 @@
"@types/node": "20.11.10",
"@types/postcss-preset-env": "7.7.0",
"@types/sortablejs": "1.15.7",
"@types/validator": "13.7.12",
"@typescript-eslint/eslint-plugin": "6.20.0",
"@typescript-eslint/parser": "6.20.0",
"@vitejs/plugin-legacy": "5.3.0",

View File

@ -214,6 +214,9 @@ dependencies:
ufo:
specifier: 1.4.0
version: 1.4.0
validator:
specifier: 13.9.0
version: 13.9.0
vue:
specifier: 3.4.15
version: 3.4.15(typescript@5.3.3)
@ -235,6 +238,9 @@ dependencies:
zhyswan-vuedraggable:
specifier: 4.1.3
version: 4.1.3(vue@3.4.15)
zod:
specifier: 3.20.6
version: 3.20.6
devDependencies:
'@4tw/cypress-drag-drop':
@ -285,6 +291,9 @@ devDependencies:
'@types/sortablejs':
specifier: 1.15.7
version: 1.15.7
'@types/validator':
specifier: 13.7.12
version: 13.7.12
'@typescript-eslint/eslint-plugin':
specifier: 6.20.0
version: 6.20.0(@typescript-eslint/parser@6.20.0)(eslint@8.56.0)(typescript@5.3.3)
@ -4918,6 +4927,10 @@ packages:
resolution: {integrity: sha512-zC0iXxAv1C1ERURduJueYzkzZ2zaGyc+P2c95hgkikHPr3z8EdUZOlgEQ5X0DRmwDZn+hekycQnoeiiRVrmilQ==}
dev: false
/@types/validator@13.7.12:
resolution: {integrity: sha512-YVtyAPqpefU+Mm/qqnOANW6IkqKpCSrarcyV269C8MA8Ux0dbkEuQwM/4CjL47kVEM2LgBef/ETfkH+c6+moFA==}
dev: true
/@types/web-bluetooth@0.0.16:
resolution: {integrity: sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ==}
dev: false
@ -11000,6 +11013,11 @@ packages:
spdx-expression-parse: 3.0.1
dev: true
/validator@13.9.0:
resolution: {integrity: sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==}
engines: {node: '>= 0.10'}
dev: false
/verror@1.10.0:
resolution: {integrity: sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==}
engines: {'0': node >=0.6.0}
@ -11784,6 +11802,10 @@ packages:
vue: 3.4.15(typescript@5.3.3)
dev: false
/zod@3.20.6:
resolution: {integrity: sha512-oyu0m54SGCtzh6EClBVqDDlAYRz4jrVtKwQ7ZnsEmMI9HnzuZFj8QFwAY1M5uniIYACdGvv0PBWPF2kO0aNofA==}
dev: false
/zod@3.22.4:
resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==}
dev: true

View File

@ -15,7 +15,7 @@ const siteId = process.env.NETLIFY_SITE_ID
const branchSlug = createSlug(process.env.DRONE_SOURCE_BRANCH)
const prNumber = process.env.DRONE_PULL_REQUEST
const prIssueCommentsUrl = `https://kolaente.dev/api/v1/repos/vikunja/frontend/issues/${prNumber}/comments`
const prIssueCommentsUrl = `https://kolaente.dev/api/v1/repos/vikunja/vikunja/issues/${prNumber}/comments`
const alias = `${prNumber}-${branchSlug}`.substring(0,37)
const fullPreviewUrl = `https://${alias}--vikunja-frontend-preview.netlify.app`

View File

@ -0,0 +1,13 @@
import type {TypeOf} from 'zod'
import {IdSchema} from './common/id'
import {AbstractSchema} from './abstract'
export const LabelTaskSchema = AbstractSchema.extend({
id: IdSchema.nullable(),
taskId: IdSchema.nullable(),
labelId: IdSchema.nullable(),
})
export type LabelTask = TypeOf<typeof LabelTaskSchema>

View File

@ -0,0 +1,10 @@
import type {TypeOf} from 'zod'
import {object, nativeEnum} from 'zod'
import {RIGHTS} from '@/constants/rights'
export const AbstractSchema = object({
maxRight: nativeEnum(RIGHTS).nullable(),
})
export type IAbstract = TypeOf<typeof AbstractSchema>

View File

@ -0,0 +1,19 @@
import type {TypeOf} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
import {UserSchema} from './user'
import {FileSchema} from './file'
export const AttachmentSchema = AbstractSchema.extend({
id: IdSchema.default(0),
taskId: IdSchema.default(0), // iTaskSchema.shape.id
createdBy: UserSchema,
file: FileSchema,
created: DateSchema.nullable(),
})
export type IAttachment = TypeOf<typeof AttachmentSchema>

View File

@ -0,0 +1,18 @@
import type {TypeOf} from 'zod'
import {z, string, object} from 'zod'
export const AVATAR_PROVIDER = [
'default',
'initials',
'gravatar',
'marble',
'upload',
] as const
export const AvatarProviderSchema = z.enum(AVATAR_PROVIDER)
export type IAvatarProvider = TypeOf<typeof AvatarProviderSchema>
export const AvatarSchema = object({
// FIXME: shouldn't the default be 'default'?
avatarProvider: string().or(AvatarProviderSchema).default(''),
})
export type IAvatar = TypeOf<typeof AvatarSchema>

View File

@ -0,0 +1,19 @@
import type {TypeOf} from 'zod'
import {object, record, string, unknown} from 'zod'
import {IdSchema} from './common/id'
export const BackgroundImageSchema = object({
id: IdSchema.default(0),
url: string().url().default(''),
thumb: string().default(''),
// FIXME: not sure if this needs to defined, since it seems provider specific
// {
// author: string(),
// authorName: string(),
// }
info: record(unknown()).default({}),
blurHash: string().default(''),
})
export type BackgroundImage = TypeOf<typeof BackgroundImageSchema>

View File

@ -0,0 +1,26 @@
import type {TypeOf} from 'zod'
import {number, array, boolean} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {TextFieldSchema} from './common/textField'
import {AbstractSchema} from './abstract'
import {UserSchema} from './user'
import {TaskSchema} from './task'
export const BucketSchema = AbstractSchema.extend({
id: IdSchema.default(0),
title: TextFieldSchema,
listId: IdSchema.default(0),
limit: number().default(0),
tasks: array(TaskSchema).default([]),
isDoneBucket: boolean().default(false),
position: number().default(0),
createdBy: UserSchema.nullable(),
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
})
export type IBucket = TypeOf<typeof BucketSchema>

View File

@ -0,0 +1,14 @@
import type {TypeOf} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
export const CaldavTokenSchema = AbstractSchema.extend({
id: IdSchema,
created: DateSchema,
})
export type CaldavToken = TypeOf<typeof CaldavTokenSchema>

View File

@ -0,0 +1,22 @@
import type {TypeOf} from 'zod'
import {nativeEnum} from 'zod'
export const RELATION_KIND = {
'SUBTASK': 'subtask',
'PARENTTASK': 'parenttask',
'RELATED': 'related',
'DUPLICATES': 'duplicates',
'BLOCKING': 'blocking',
'BLOCKED': 'blocked',
'PROCEDES': 'precedes',
'FOLLOWS': 'follows',
'COPIEDFROM': 'copiedfrom',
'COPIEDTO': 'copiedto',
} as const
export const RELATION_KINDS = [...Object.values(RELATION_KIND)] as const
export const RelationKindSchema = nativeEnum(RELATION_KIND)
export type IRelationKind = TypeOf<typeof RelationKindSchema>

View File

@ -0,0 +1,11 @@
import {preprocess, date} from 'zod'
export const DateSchema = preprocess((arg) => {
if (
// FIXME: Add comment why we check for `0001`
typeof arg == 'string' && !arg.startsWith('0001') ||
arg instanceof Date
) {
return new Date(arg)
}
}, date())

View File

@ -0,0 +1,80 @@
import type {TypeOf} from 'zod'
import {z, nativeEnum, array, boolean, object, number} from 'zod'
export enum SORT_BY {
ID = 'id',
DONE = 'done',
TITLE = 'title',
PRIORITY = 'priority',
DONE_AT = 'done_at',
DUE_DATE = 'due_date',
START_DATE = 'start_date',
END_DATE = 'end_date',
PERCENT_DONE = 'percent_done',
CREATED = 'created',
UPDATED = 'updated',
POSITION = 'position',
KANBAN_POSITION = 'kanban_position',
}
export enum ORDER_BY {
ASC = 'asc',
DESC = 'desc',
NONE = 'none',
}
export enum FILTER_BY {
DONE = 'done',
DUE_DATE = 'due_date',
START_DATE = 'start_date',
END_DATE = 'end_date',
NAMESPACE = 'namespace',
ASSIGNEES = 'assignees',
LIST_ID = 'list_id',
BUCKET_ID = 'bucket_id',
PRIORITY = 'priority',
PERCENT_DONE = 'percent_done',
LABELS = 'labels',
UNDEFINED = 'undefined', // FIXME: Why do we have a value that is undefined as string?
}
export enum FILTER_COMPARATOR {
EQUALS = 'equals',
LESS = 'less',
GREATER = 'greater',
GREATER_EQUALS = 'greater_equals',
LESS_EQUALS = 'less_equals',
IN = 'in',
}
export enum FILTER_CONCAT {
AND = 'and',
OR = 'or',
IN = 'in',
}
const TASKS_PER_BUCKET = 25
export const FilterSchema = object({
sortBy: array(nativeEnum(SORT_BY)).default([SORT_BY.DONE, SORT_BY.ID]), // FIXME: create from taskSchema,
// fixme default order seem so also be `desc`
// see line from ListTable:
// if (typeof order === 'undefined' || order === 'none') {
orderBy: array(nativeEnum(ORDER_BY)).default([ORDER_BY.ASC, ORDER_BY.DESC]),
// FIXME: create from taskSchema
filterBy: array(nativeEnum(FILTER_BY)).default([FILTER_BY.DONE]),
// FIXME: create from taskSchema
// FIXME: might need to preprocess values, e.g. date.
// see line from 'filters.vue':
// params.filter_value = params.filter_value.map(v => v instanceof Date ? v.toISOString() : v)
filterValue: array(z.enum(['false'])).default(['false']),
// FIXME: is `in` value correct?
// found in `quick-actions.vue`:
// params.filter_comparator.push('in')
filterComparator: array(nativeEnum(FILTER_COMPARATOR)).default([FILTER_COMPARATOR.EQUALS]),
filterConcat: z.nativeEnum(FILTER_CONCAT).default(FILTER_CONCAT.AND),
filterIncludeNulls: boolean().default(true),
perPage: number().default(TASKS_PER_BUCKET), // FIXME: is perPage is just available for the bucket endpoint?
})
export type IFilter = TypeOf<typeof FilterSchema>

View File

@ -0,0 +1,10 @@
import {string} from 'zod'
import isHexColor from 'validator/lib/isHexColor'
export const HexColorSchema = string().transform(
(value) => {
if (!value || value.startsWith('#')) {
return value
}
return '#' + value
}).refine(value => isHexColor(value))

View File

@ -0,0 +1,6 @@
import {number, preprocess} from 'zod'
export const IdSchema = preprocess(
(value: unknown) => Number(value),
number().positive().int(),
)

View File

@ -1,24 +1,26 @@
import type {TypeOf} from 'zod'
import {nativeEnum, number, object, preprocess} from 'zod'
import {SECONDS_A_HOUR} from '@/constants/date'
import { REPEAT_TYPES, type IRepeatAfter } from '@/types/IRepeatAfter'
import { nativeEnum, number, object, preprocess } from 'zod'
import {REPEAT_TYPES, type IRepeatAfter} from '@/types/IRepeatAfter'
/**
* Parses `repeatAfterSeconds` into a usable js object.
*/
export function parseRepeatAfter(repeatAfterSeconds: number): IRepeatAfter {
let repeatAfter: IRepeatAfter = {type: 'hours', amount: repeatAfterSeconds / SECONDS_A_HOUR}
let repeatAfter: IRepeatAfter
// if its dividable by 24, its something with days, otherwise hours
// if its dividable by SECONDS_A_DAY, its something with days, otherwise hours
if (repeatAfterSeconds % SECONDS_A_DAY === 0) {
if (repeatAfterSeconds % SECONDS_A_WEEK === 0) {
repeatAfter = {type: 'weeks', amount: repeatAfterSeconds / SECONDS_A_WEEK}
} else if (repeatAfterSeconds % SECONDS_A_MONTH === 0) {
repeatAfter = {type:'months', amount: repeatAfterSeconds / SECONDS_A_MONTH}
} else if (repeatAfterSeconds % SECONDS_A_YEAR === 0) {
repeatAfter = {type: 'years', amount: repeatAfterSeconds / SECONDS_A_YEAR}
} else {
repeatAfter = {type: 'days', amount: repeatAfterSeconds / SECONDS_A_DAY}
}
repeatAfter = {type: REPEAT_TYPES.HOURS, amount: repeatAfterSeconds / SECONDS_A_HOUR}
} else if (repeatAfterSeconds % SECONDS_A_WEEK === 0) {
repeatAfter = {type: REPEAT_TYPES.WEEKS, amount: repeatAfterSeconds / SECONDS_A_WEEK}
} else if (repeatAfterSeconds % SECONDS_A_MONTH === 0) {
repeatAfter = {type: REPEAT_TYPES.MONTHS, amount: repeatAfterSeconds / SECONDS_A_MONTH}
} else if (repeatAfterSeconds % SECONDS_A_YEAR === 0) {
repeatAfter = {type: REPEAT_TYPES.YEARS, amount: repeatAfterSeconds / SECONDS_A_YEAR}
} else {
repeatAfter = {type: REPEAT_TYPES.DAYS, amount: repeatAfterSeconds / SECONDS_A_DAY}
}
return repeatAfter
}
@ -37,4 +39,6 @@ export const RepeatsSchema = preprocess(
type: nativeEnum(REPEAT_TYPES),
amount: number().int(),
}),
)
)
export type RepeatAfter = TypeOf<typeof RepeatsSchema>

View File

@ -0,0 +1,3 @@
import {string} from 'zod'
export const TextFieldSchema = string().transform((value) => value.trim()).default('')

View File

@ -0,0 +1,11 @@
import type {TypeOf} from 'zod'
import {string} from 'zod'
import {AbstractSchema} from './abstract'
export const EmailUpdateSchema = AbstractSchema.extend({
newEmail: string().email().default(''),
password: string().default(''),
})
export type EmailUpdate = TypeOf<typeof EmailUpdateSchema>

View File

@ -0,0 +1,15 @@
import type {TypeOf} from 'zod'
import {object, number, string} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
export const FileSchema = object({
id: IdSchema.default(0),
mime: string().default(''),
name: string().default(''),
size: number().default(0),
created: DateSchema.nullable(),
})
export type File = TypeOf<typeof FileSchema>

View File

@ -0,0 +1,33 @@
import type {TypeOf} from 'zod'
import {string} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {HexColorSchema} from './common/hexColor'
import {UserSchema} from './user'
import {AbstractSchema} from './abstract'
import {colorIsDark} from '@/helpers/color/colorIsDark'
const DEFAULT_LABEL_BACKGROUND_COLOR = 'e8e8e8'
export const LabelSchema = AbstractSchema.extend({
id: IdSchema.default(0),
title: string().default(''),
hexColor: HexColorSchema.default(DEFAULT_LABEL_BACKGROUND_COLOR),
textColor: string(), // implicit
description: string().default(''),
createdBy: UserSchema, // FIXME: default: current user?
listId: IdSchema.default(0),
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
}).transform((obj) => {
// FIXME: remove textColor location => should be defined in UI
obj.textColor = colorIsDark(obj.hexColor) ? '#4a4a4a' : '#ffffff'
return obj
},
)
export type ILabel = TypeOf<typeof LabelSchema>

View File

@ -0,0 +1,26 @@
import type {TypeOf} from 'zod'
import {number, string, nativeEnum} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
import {UserSchema} from './user'
import {RIGHTS} from '@/constants/rights'
export const LinkShareSchema = AbstractSchema.extend({
id: IdSchema.default(0),
hash: string().default(''),
right: nativeEnum(RIGHTS).default(RIGHTS.READ),
sharedBy: UserSchema,
sharingType: number().default(0), // FIXME: use correct numbers
listId: IdSchema.default(0),
name: string().default(''),
password: string().default(''),
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
})
export type LinkShare = TypeOf<typeof LinkShareSchema>

View File

@ -0,0 +1,32 @@
import type {TypeOf} from 'zod'
import {boolean, number, string, array, any} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
import {SubscriptionSchema} from './subscription'
import {TaskSchema} from './task'
import {UserSchema} from './user'
export const ListSchema = AbstractSchema.extend({
id: IdSchema.default(0),
hash: string().default(''),
description: string().default(''),
owner: UserSchema,
tasks: array(TaskSchema),
namespaceId: IdSchema.default(0), // INamespace['id'],
isArchived: boolean().default(false),
hexColor: string().default(''),
identifier: string().default(''),
backgroundInformation: any().nullable().default(null), // FIXME: what is this for?
isFavorite: boolean().default(false),
subscription: SubscriptionSchema.nullable(),
position: number().default(0),
backgroundBlurHash: string().default(''),
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
})
export type List = TypeOf<typeof ListSchema>

View File

@ -0,0 +1,14 @@
import type {TypeOf} from 'zod'
import {IdSchema} from './common/id'
import {AbstractSchema} from './abstract'
import {ListSchema} from './list'
export const ListDuplicationSchema = AbstractSchema.extend({
listId: IdSchema.default(0),
namespaceId: IdSchema.default(0), // INamespace['id'],
list: ListSchema,
})
export type ListDuplication = TypeOf<typeof ListDuplicationSchema>

View File

@ -0,0 +1,26 @@
import type {TypeOf} from 'zod'
import {boolean, string, array} from 'zod'
import {IdSchema} from './common/id'
import {HexColorSchema} from './common/hexColor'
import {AbstractSchema} from './abstract'
import {ListSchema} from './list'
import {UserSchema} from './user'
import {SubscriptionSchema} from './subscription'
export const NamespaceSchema = AbstractSchema.extend({
id: IdSchema.default(0),
title: string().default(''),
description: string().default(''),
owner: UserSchema,
lists: array(ListSchema),
isArchived: boolean().default(false),
hexColor: HexColorSchema.default(''),
subscription: SubscriptionSchema.nullable(),
created: IdSchema.nullable(),
updated: IdSchema.nullable(),
})
export type Namespace = TypeOf<typeof NamespaceSchema>

View File

@ -0,0 +1,54 @@
import type {TypeOf} from 'zod'
import {union, boolean, object, string} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
import {TaskSchema} from './task'
import {TaskCommentSchema} from './taskComment'
import {TeamSchema} from './team'
import {UserSchema} from './user'
const NotificationTypeSchema = object({
doer: UserSchema,
})
const NotificationTypeTask = NotificationTypeSchema.extend({
task: TaskSchema,
comment: TaskCommentSchema,
})
const NotificationTypeAssigned = NotificationTypeSchema.extend({
task: TaskSchema,
assignee: UserSchema,
})
const NotificationTypeDeleted = NotificationTypeSchema.extend({
task: TaskSchema,
})
const NotificationTypeCreated = NotificationTypeSchema.extend({
task: TaskSchema,
})
const NotificationTypeMemberAdded = NotificationTypeSchema.extend({
member: UserSchema,
team: TeamSchema,
})
export const NotificationSchema = AbstractSchema.extend({
id: IdSchema.default(0),
name: string().default(''),
notification: union([
NotificationTypeTask,
NotificationTypeAssigned,
NotificationTypeDeleted,
NotificationTypeCreated,
NotificationTypeMemberAdded,
]),
read: boolean().default(false),
readAt: DateSchema.nullable(),
})
export type Notification = TypeOf<typeof NotificationSchema>

View File

@ -0,0 +1,13 @@
import type {TypeOf} from 'zod'
import {string} from 'zod'
import {AbstractSchema} from './abstract'
// FIXME: is it correct that this extends the Abstract Schema?
export const PasswordResetSchema = AbstractSchema.extend({
token: string().default(''),
newPassword: string().default(''),
email: string().email().default(''),
})
export type PasswordReset = TypeOf<typeof PasswordResetSchema>

View File

@ -0,0 +1,15 @@
import type {TypeOf} from 'zod'
import {string} from 'zod'
import {AbstractSchema} from './abstract'
// FIXME: is it correct that this extends the Abstract Schema?
export const PasswordUpdateSchema = AbstractSchema.extend({
newPassword: string().default(''),
oldPassword: string().default(''),
}).refine((data) => data.newPassword === data.oldPassword, {
message: 'Passwords don\'t match',
path: ['confirm'], // path of error
})
export type PasswordUpdate = TypeOf<typeof PasswordUpdateSchema>

View File

@ -0,0 +1,23 @@
import type {TypeOf} from 'zod'
import {string} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {FilterSchema} from './common/filter'
import {AbstractSchema} from './abstract'
import {UserSchema} from './user'
// FIXME: is it correct that this extends the Abstract Schema?
export const SavedFilterSchema = AbstractSchema.extend({
id: IdSchema.default(0),
title: string().default(''),
description: string().default(''),
filters: FilterSchema,
owner: UserSchema,
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
})
export type SavedFilter = TypeOf<typeof SavedFilterSchema>

View File

@ -0,0 +1,19 @@
import type {TypeOf} from 'zod'
import {string} from 'zod'
import {DateSchema} from './common/date'
import {IdSchema} from './common/id'
import {AbstractSchema} from './abstract'
import {UserSchema} from './user'
export const SubscriptionSchema = AbstractSchema.extend({
id: IdSchema.default(0),
entity: string().default(''), // FIXME: correct type?
entityId: IdSchema.default(0), // FIXME: correct type?
user: UserSchema,
created: DateSchema.nullable(),
})
export type Subscription = TypeOf<typeof SubscriptionSchema>

View File

@ -0,0 +1,119 @@
import type {ZodType, TypeOf} from 'zod'
import {nativeEnum, boolean, number, string, array, record, unknown, lazy} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {HexColorSchema} from './common/hexColor'
import {TextFieldSchema} from './common/textField'
import {RelationKindSchema} from './common/RelationKind'
import {RepeatsSchema} from './common/repeats'
import {AbstractSchema} from './abstract'
import {AttachmentSchema} from './attachment'
import {LabelSchema} from './label'
import {SubscriptionSchema} from './subscription'
import {UserSchema} from './user'
import {PRIORITIES} from '@/constants/priorities'
import {TASK_REPEAT_MODES} from '@/types/IRepeatMode'
const LabelsSchema = array(LabelSchema)
.transform((labels) => labels.sort((f, s) => f.title > s.title ? 1 : -1)) // FIXME: use
.default([])
export type ILabels = TypeOf<typeof LabelsSchema>
const RelatedTasksSchema = record(RelationKindSchema, record(string(), unknown()))
export type IRelatedTasksSchema = TypeOf<typeof RelatedTasksSchema>
const RelatedTasksLazySchema : ZodType<Task['relatedTasks']> = lazy(() =>
record(RelationKindSchema, TaskSchema),
)
export type IRelatedTasksLazySchema = TypeOf<typeof RelatedTasksLazySchema>
// export interface ITask extends IAbstract {
// id: number
// title: string
// description: string
// done: boolean
// doneAt: Date | null
// priority: Priority
// labels: ILabel[]
// assignees: IUser[]
// dueDate: Date | null
// startDate: Date | null
// endDate: Date | null
// repeatAfter: number | IRepeatAfter
// repeatFromCurrentDate: boolean
// repeatMode: IRepeatMode
// reminderDates: Date[]
// parentTaskId: ITask['id']
// hexColor: string
// percentDone: number
// relatedTasks: Partial<Record<IRelationKind, ITask>>,
// attachments: IAttachment[]
// identifier: string
// index: number
// isFavorite: boolean
// subscription: ISubscription
// position: number
// kanbanPosition: number
// createdBy: IUser
// created: Date
// updated: Date
// listId: IList['id'] // Meta, only used when creating a new task
// bucketId: IBucket['id']
// }
export const TaskSchema = AbstractSchema.extend({
id: IdSchema.default(0),
title: TextFieldSchema,
description: TextFieldSchema,
done: boolean().default(false),
doneAt: DateSchema.nullable().default(null),
priority: nativeEnum(PRIORITIES).default(PRIORITIES.UNSET),
labels: LabelsSchema,
assignees: array(UserSchema).default([]),
dueDate: DateSchema.nullable(), // FIXME: default value is `0`. Shouldn't this be `null`?
startDate: DateSchema.nullable(), // FIXME: default value is `0`. Shouldn't this be `null`?
endDate: DateSchema.nullable(), // FIXME: default value is `0`. Shouldn't this be `null`?
repeatAfter: RepeatsSchema, // FIXME: default value is `0`. Shouldn't this be `null`?
repeatFromCurrentDate: boolean().default(false),
repeatMode: nativeEnum(TASK_REPEAT_MODES).default(TASK_REPEAT_MODES.REPEAT_MODE_DEFAULT),
// TODO: schedule notifications
// FIXME: triggered notificaitons not supported anymore / remove feature?
reminderDates: array(DateSchema).default([]),
parentTaskId: IdSchema.default(0), // shouldn't this have `null` as default?
hexColor: HexColorSchema.default(''),
percentDone: number().default(0),
relatedTasks: RelatedTasksSchema.default({}),
attachments: array(AttachmentSchema).default([]),
identifier: string().default(''),
index: number().default(0),
isFavorite: boolean().default(false),
subscription: SubscriptionSchema.nullable().default(null),
position: number().default(0),
kanbanPosition: number().default(0),
createdBy: UserSchema,
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
listId: IdSchema.default(0), //IList['id'], // Meta, only used when creating a new task
bucketId: IdSchema.default(0), // IBucket['id'],
}).transform((obj) => {
if (obj.identifier === `-${obj.index}`) {
obj.identifier = ''
}
return obj
})
export type Task = TypeOf<typeof TaskSchema>

View File

@ -0,0 +1,14 @@
import type {TypeOf} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
export const TaskAssigneeSchema = AbstractSchema.extend({
created: DateSchema.nullable(),
userId: IdSchema.default(0), // IUser['id']
taskId: IdSchema.default(0), // ITask['id']
})
export type TaskAssignee = TypeOf<typeof TaskAssigneeSchema>

View File

@ -0,0 +1,20 @@
import type {TypeOf} from 'zod'
import {string} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
import {UserSchema} from './user'
export const TaskCommentSchema = AbstractSchema.extend({
id: IdSchema.default(0),
taskId: IdSchema.default(0),
comment: string().default(''),
author: UserSchema,
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
})
export type TaskComment = TypeOf<typeof TaskCommentSchema>

View File

@ -0,0 +1,24 @@
import type {TypeOf} from 'zod'
import {nativeEnum} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
import {UserSchema} from './user'
import {RELATION_KIND} from '@/types/IRelationKind'
export const TaskRelationSchema = AbstractSchema.extend({
id: IdSchema.default(0),
otherTaskId: IdSchema.default(0),
taskId: IdSchema.default(0),
relationKind: nativeEnum(RELATION_KIND).nullable().default(null), // FIXME: default value was empty string?
createdBy: UserSchema,
// FIXME: shouldn't the empty value of dates be `new Date()`
// Because e.g. : `new Date(null)` => Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)
created: DateSchema.nullable().default(null),
})
export type ITaskRelation = TypeOf<typeof TaskRelationSchema>

View File

@ -0,0 +1,25 @@
import type {TypeOf} from 'zod'
import {array, nativeEnum, string} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
import {UserSchema} from './user'
import {TeamMemberSchema} from './teamMember'
import {RIGHTS} from '@/constants/rights'
export const TeamSchema = AbstractSchema.extend({
id: IdSchema.default(0),
name: string().default(''),
description: string().default(''),
members: array(TeamMemberSchema),
right: nativeEnum(RIGHTS).default(RIGHTS.READ),
createdBy: UserSchema, // FIXME: default was {},
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
})
export type Team = TypeOf<typeof TeamSchema>

View File

@ -0,0 +1,11 @@
import type {TypeOf} from 'zod'
import {IdSchema} from './common/id'
import {TeamShareBaseSchema} from './teamShareBase'
export const TeamListSchema = TeamShareBaseSchema.extend({
listId: IdSchema.default(0), // IList['id']
})
export type TeamList = TypeOf<typeof TeamListSchema>

View File

@ -0,0 +1,13 @@
import type {TypeOf} from 'zod'
import {boolean} from 'zod'
import {IdSchema} from './common/id'
import {UserSchema} from './user'
export const TeamMemberSchema = UserSchema.extend({
admin: boolean().default(false),
teamId: IdSchema.default(0), // IList['id']
})
export type TeamMember = TypeOf<typeof TeamMemberSchema>

View File

@ -0,0 +1,11 @@
import type {TypeOf} from 'zod'
import {IdSchema} from './common/id'
import {TeamShareBaseSchema} from './teamShareBase'
export const TeamNamespaceSchema = TeamShareBaseSchema.extend({
namespaceId: IdSchema.default(0), // INamespace['id']
})
export type ITeamNamespace = TypeOf<typeof TeamNamespaceSchema>

View File

@ -0,0 +1,19 @@
import type {TypeOf} from 'zod'
import {nativeEnum} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
import {RIGHTS} from '@/constants/rights'
export const TeamShareBaseSchema = AbstractSchema.extend({
teamId: IdSchema.default(0), // ITeam['id']
right: nativeEnum(RIGHTS).default(RIGHTS.READ),
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
})
export type ITeamShareBase = TypeOf<typeof TeamShareBaseSchema>

View File

@ -0,0 +1,9 @@
import type {TypeOf} from 'zod'
import {object, string} from 'zod'
export const TokenSchema = object({
token: string(),
})
export type IToken = TypeOf<typeof TokenSchema>

View File

@ -0,0 +1,12 @@
import type {TypeOf} from 'zod'
import {string, boolean} from 'zod'
import {AbstractSchema} from './abstract'
export const TotpSchema = AbstractSchema.extend({
secret: string().default(''),
enabled: boolean().default(false),
url: string().url().default(''),
})
export type Totp = TypeOf<typeof TotpSchema>

View File

@ -0,0 +1,21 @@
import type {TypeOf} from 'zod'
import {string} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
import {UserSettingsSchema} from './userSettings'
export const UserSchema = AbstractSchema.extend({
id: IdSchema.default(0),
email: string().email().default(''),
username: string().default(''),
name: string().default(''),
settings: UserSettingsSchema.nullable(),
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
})
export type User = TypeOf<typeof UserSchema>

View File

@ -0,0 +1,11 @@
import type {TypeOf} from 'zod'
import {IdSchema} from './common/id'
import {UserShareBaseSchema} from './userShareBase'
export const UserListSchema = UserShareBaseSchema.extend({
listId: IdSchema.default(0), // IList['id']
})
export type IUserList = TypeOf<typeof UserListSchema>

View File

@ -0,0 +1,11 @@
import type {TypeOf} from 'zod'
import {IdSchema} from './common/id'
import {UserShareBaseSchema} from './userShareBase'
export const UserNamespaceSchema = UserShareBaseSchema.extend({
namespaceId: IdSchema.default(0), // INamespace['id']
})
export type IUserNamespace = TypeOf<typeof UserNamespaceSchema>

View File

@ -0,0 +1,29 @@
import type {TypeOf} from 'zod'
import {boolean, string, undefined, nativeEnum} from 'zod'
import {IdSchema} from './common/id'
import {AbstractSchema} from './abstract'
const WEEKDAYS = {
MONDAY: 0,
TUESDAY: 1,
WEDNESDAY: 2,
THURSDAY: 3,
FRIDAY: 4,
SATURDAY: 5,
SUNDAY: 6,
} as const
export const UserSettingsSchema = AbstractSchema.extend({
name: string().default(''),
emailRemindersEnabled: boolean().default(true),
discoverableByName: boolean().default(false),
discoverableByEmail: boolean().default(false),
overdueTasksRemindersEnabled: boolean().default(true),
defaultListId: IdSchema.or(undefined()), // iListSchema['id'] // FIXME: shouldn't this be `null`?
weekStart: nativeEnum(WEEKDAYS).default(WEEKDAYS.MONDAY),
timezone: string().default(''),
})
export type IUserSettings = TypeOf<typeof UserSettingsSchema>

View File

@ -0,0 +1,19 @@
import type {TypeOf} from 'zod'
import {nativeEnum} from 'zod'
import {IdSchema} from './common/id'
import {DateSchema} from './common/date'
import {AbstractSchema} from './abstract'
import {RIGHTS} from '@/constants/rights'
export const UserShareBaseSchema = AbstractSchema.extend({
userId: IdSchema, // FIXME: default of model is `''`
right: nativeEnum(RIGHTS).default(RIGHTS.READ),
created: DateSchema.nullable(),
updated: DateSchema.nullable(),
})
export type TeamMember = TypeOf<typeof UserShareBaseSchema>

View File

@ -1,6 +1,13 @@
import type {IAbstract} from './IAbstract'
export type AvatarProvider = 'default' | 'initials' | 'gravatar' | 'marble' | 'upload'
export const AVATAR_PROVIDER = [
'default',
'initials',
'gravatar',
'marble',
'upload',
] as const
export type AvatarProvider = typeof AVATAR_PROVIDER[number]
export interface IAvatar extends IAbstract {
avatarProvider: AvatarProvider

View File

@ -218,7 +218,7 @@ func registerAPIRoutes(a *echo.Group) {
// Echo does not unescape url path params by default. To make sure values bound as :param in urls are passed
// properly to handlers, we use this middleware to unescape them.
// See https://kolaente.dev/vikunja/api/issues/1224
// See https://kolaente.dev/vikunja/vikunja/issues/1224
// See https://github.com/labstack/echo/issues/766
a.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {