Skip to content

Commit

Permalink
Fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Mar 12, 2024
1 parent e15b7b9 commit e9569ad
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/Http/Requests/V1/TimeEntry/TimeEntryIndexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function rules(): array
],
// Filter only time entries that are active (have no end date, are still running)
'active' => [
'boolean',
'string',
'in:true,false',
],
// Limit the number of returned time entries
'limit' => [
Expand Down
4 changes: 4 additions & 0 deletions app/Service/Import/ImportDatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ class ImportDatabaseHelper

private int $createdCount;

/**
* @var array<string, array<int, string>>
*/
private array $validate;

/**
* @param class-string<TModel> $model
* @param array<string> $identifiers
* @param array<string, array<int, string>> $validate
*/
public function __construct(string $model, array $identifiers, bool $attachToExisting = false, ?Closure $queryModifier = null, ?Closure $afterCreate = null, array $validate = [])
{
Expand Down
162 changes: 160 additions & 2 deletions openapi.json.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const ClientResource = z
})
.passthrough();
const ClientCollection = z.array(ClientResource);
const v1_import_import_Body = z
.object({ type: z.string(), data: z.string() })
.passthrough();
const OrganizationResource = z
.object({ id: z.string(), name: z.string(), is_personal: z.string() })
.passthrough();
Expand Down Expand Up @@ -72,10 +75,21 @@ const updateTimeEntry_Body = z
tags: z.union([z.array(z.string()), z.null()]).optional(),
})
.passthrough();
const UserResource = z
.object({
id: z.string(),
name: z.string(),
email: z.string(),
role: z.string(),
is_placeholder: z.boolean(),
})
.passthrough();
const UserCollection = z.array(UserResource);

export const schemas = {
ClientResource,
ClientCollection,
v1_import_import_Body,
OrganizationResource,
ProjectResource,
ProjectCollection,
Expand All @@ -87,6 +101,8 @@ export const schemas = {
TimeEntryCollection,
createTimeEntry_Body,
updateTimeEntry_Body,
UserResource,
UserCollection,
};

const endpoints = makeApi([
Expand Down Expand Up @@ -306,6 +322,76 @@ const endpoints = makeApi([
},
],
},
{
method: 'post',
path: '/v1/organizations/:organization/import',
alias: 'v1.import.import',
requestFormat: 'json',
parameters: [
{
name: 'body',
type: 'Body',
schema: v1_import_import_Body,
},
{
name: 'organization',
type: 'Path',
schema: z.string().uuid(),
},
],
response: z
.object({
report: z
.object({
clients: z
.object({ created: z.number().int() })
.passthrough(),
projects: z
.object({ created: z.number().int() })
.passthrough(),
tasks: z
.object({ created: z.number().int() })
.passthrough(),
'time-entries': z
.object({ created: z.number().int() })
.passthrough(),
tags: z
.object({ created: z.number().int() })
.passthrough(),
users: z
.object({ created: z.number().int() })
.passthrough(),
})
.passthrough(),
})
.passthrough(),
errors: [
{
status: 400,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 403,
description: `Authorization error`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 404,
description: `Not found`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 422,
description: `Validation error`,
schema: z
.object({
message: z.string(),
errors: z.record(z.array(z.string())),
})
.passthrough(),
},
],
},
{
method: 'get',
path: '/v1/organizations/:organization/projects',
Expand Down Expand Up @@ -664,7 +750,7 @@ const endpoints = makeApi([
{
name: 'active',
type: 'Query',
schema: z.string().optional(),
schema: z.enum(['true', 'false']).optional(),
},
{
name: 'limit',
Expand Down Expand Up @@ -824,9 +910,81 @@ const endpoints = makeApi([
},
],
},
{
method: 'get',
path: '/v1/organizations/:organization/users',
alias: 'v1.users.index',
requestFormat: 'json',
parameters: [
{
name: 'organization',
type: 'Path',
schema: z.string().uuid(),
},
],
response: z.object({ data: UserCollection }).passthrough(),
errors: [
{
status: 403,
description: `Authorization error`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 404,
description: `Not found`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 422,
description: `Validation error`,
schema: z
.object({
message: z.string(),
errors: z.record(z.array(z.string())),
})
.passthrough(),
},
],
},
{
method: 'post',
path: '/v1/organizations/:organization/users/:user/invite-placeholder',
alias: 'v1.users.invite-placeholder',
requestFormat: 'json',
parameters: [
{
name: 'body',
type: 'Body',
schema: z.object({}).partial().passthrough(),
},
{
name: 'organization',
type: 'Path',
schema: z.string().uuid(),
},
{
name: 'user',
type: 'Path',
schema: z.string().uuid(),
},
],
response: z.string(),
errors: [
{
status: 403,
description: `Authorization error`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 404,
description: `Not found`,
schema: z.object({ message: z.string() }).passthrough(),
},
],
},
]);

export const api = new Zodios('http://solidtime.test/api', endpoints);
export const api = new Zodios('https://solidtime.test/api', endpoints);

export function createApiClient(baseUrl: string, options?: ZodiosOptions) {
return new Zodios(baseUrl, endpoints, options);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint:fix": "eslint --fix --ext .js,.vue,.ts --ignore-path .gitignore .",
"type-check": "vue-tsc --noEmit",
"test:e2e": "npx playwright test",
"generate:zod": "npx openapi-zod-client http://localhost:80/docs/api.json --output openapi.json.client.ts --base-url http://solidtime.test/api"
"generate:zod": "npx openapi-zod-client http://localhost:80/docs/api.json --output openapi.json.client.ts --base-url https://solidtime.test/api"
},
"devDependencies": {
"@inertiajs/vue3": "^1.0.0",
Expand Down

0 comments on commit e9569ad

Please sign in to comment.