Skip to content

Commit

Permalink
fix: improve typing (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
batopa authored Feb 21, 2024
1 parent 1328327 commit 6361058
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/runtime/composables/useBeditaSignup.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { useRecaptcha } from '../composables/useRecaptcha';
import { useRoute, useFetch } from '#imports';
import { useRoute } from '#imports';
import type { AsyncData } from '#app';
import type { SignupBeditaBody } from '../types';
import { RecaptchaActions } from '../utils/recaptcha-helpers';
import type { ApiResponseBodyError, JsonApiResourceObject } from '@atlasconsulting/bedita-sdk';
import type { FetchError } from 'ofetch';

export const useBeditaSignup = () => {
const { executeRecaptcha } = useRecaptcha();

const signup = async (data: SignupBeditaBody) => {
const recaptcha_token = await executeRecaptcha(RecaptchaActions.SIGNUP);
return await $fetch('/api/bedita/signup', {
return await $fetch<JsonApiResourceObject>('/api/bedita/signup', {
method: 'POST',
body: {
...data,
Expand All @@ -17,10 +20,10 @@ export const useBeditaSignup = () => {
});
};

const signupActivation = async (uuid?: string, server?: boolean) => {
const signupActivation = (uuid?: string, server?: boolean): AsyncData<{ activated: true;} | null, FetchError<ApiResponseBodyError> | null> => {
const route = useRoute();

return await useFetch('/api/bedita/signup/activation', {
return useFetch('/api/bedita/signup/activation', {
method:'POST',
body: { uuid: uuid || route.query?.uuid },
server,
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/server/api/bedita/signup/activation.post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineEventHandler, readBody } from 'h3';
import { beditaApiClient, handleBeditaApiError } from '../../../utils/bedita-api-client';
import type { ApiResponseBodyError } from '@atlasconsulting/bedita-sdk';

export default defineEventHandler(async (event) => {
export default defineEventHandler(async (event): Promise<{ activated: true; } | ApiResponseBodyError> => {
try {
const body = await readBody(event);
const client = await beditaApiClient(event);
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/server/api/bedita/signup/signup.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { defineEventHandler, readBody } from 'h3';
import { recaptchaVerifyToken } from '../../../utils/recaptcha';
import { beditaApiClient, handleBeditaApiError } from '../../../utils/bedita-api-client';
import { RecaptchaActions } from '../../../../utils/recaptcha-helpers';
import { type JsonApiResourceObject } from '@atlasconsulting/bedita-sdk';
import { type ApiResponseBodyError, type JsonApiResourceObject } from '@atlasconsulting/bedita-sdk';

export default defineEventHandler(async (event) => {
export default defineEventHandler(async (event): Promise<JsonApiResourceObject | ApiResponseBodyError> => {
try {
const body = await readBody(event);

Expand Down

0 comments on commit 6361058

Please sign in to comment.