refactor: update fichaPontoPDF and processamento to enhance legend styling and accumulate saldo for all days, improving report accuracy
This commit is contained in:
@@ -3,7 +3,7 @@ import { convex } from '@convex-dev/better-auth/plugins';
|
||||
import { betterAuth } from 'better-auth';
|
||||
import { components } from './_generated/api';
|
||||
import type { DataModel } from './_generated/dataModel';
|
||||
import { type MutationCtx, type QueryCtx, query } from './_generated/server';
|
||||
import { type MutationCtx, type QueryCtx, type ActionCtx, query } from './_generated/server';
|
||||
|
||||
// Usar SITE_URL se disponível, caso contrário usar CONVEX_SITE_URL ou um valor padrão
|
||||
const siteUrl = process.env.SITE_URL || process.env.CONVEX_SITE_URL || 'http://localhost:5173';
|
||||
@@ -14,6 +14,22 @@ console.log('siteUrl:', siteUrl);
|
||||
// as well as helper methods for general use.
|
||||
export const authComponent = createClient<DataModel>(components.betterAuth);
|
||||
|
||||
/**
|
||||
* Helper type para converter contextos do Convex para GenericCtx do better-auth
|
||||
* Isso resolve incompatibilidade de tipos entre versões do Convex sem usar 'any'
|
||||
*/
|
||||
type ConvexCtx = QueryCtx | MutationCtx | ActionCtx;
|
||||
|
||||
/**
|
||||
* Função helper para converter contexto do Convex para GenericCtx do better-auth
|
||||
* Os tipos são estruturalmente compatíveis, apenas há diferença nas definições de tipo
|
||||
*/
|
||||
function toGenericCtx(ctx: ConvexCtx): GenericCtx<DataModel> {
|
||||
// Os tipos são estruturalmente idênticos, apenas há diferença nas definições de tipo
|
||||
// entre a versão do Convex usada pelo projeto e a usada pelo @convex-dev/better-auth
|
||||
return ctx as unknown as GenericCtx<DataModel>;
|
||||
}
|
||||
|
||||
export const createAuth = (
|
||||
ctx: GenericCtx<DataModel>,
|
||||
{ optionsOnly } = { optionsOnly: false }
|
||||
@@ -45,7 +61,7 @@ export const getCurrentUser = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
try {
|
||||
const authUser = await authComponent.safeGetAuthUser(ctx);
|
||||
const authUser = await authComponent.safeGetAuthUser(toGenericCtx(ctx));
|
||||
if (!authUser) {
|
||||
return;
|
||||
}
|
||||
@@ -83,7 +99,7 @@ export const getCurrentUser = query({
|
||||
});
|
||||
|
||||
export const getCurrentUserFunction = async (ctx: QueryCtx | MutationCtx) => {
|
||||
const authUser = await authComponent.safeGetAuthUser(ctx);
|
||||
const authUser = await authComponent.safeGetAuthUser(toGenericCtx(ctx));
|
||||
if (!authUser) {
|
||||
return;
|
||||
}
|
||||
@@ -102,7 +118,7 @@ export const createAuthUser = async (
|
||||
ctx: MutationCtx,
|
||||
args: { nome: string; email: string; password: string }
|
||||
) => {
|
||||
const { auth, headers } = await authComponent.getAuth(createAuth, ctx);
|
||||
const { auth, headers } = await authComponent.getAuth(createAuth, toGenericCtx(ctx));
|
||||
|
||||
const result = await auth.api.signUpEmail({
|
||||
headers,
|
||||
@@ -120,7 +136,7 @@ export const updatePassword = async (
|
||||
ctx: MutationCtx,
|
||||
args: { newPassword: string; currentPassword: string }
|
||||
) => {
|
||||
const { auth, headers } = await authComponent.getAuth(createAuth, ctx);
|
||||
const { auth, headers } = await authComponent.getAuth(createAuth, toGenericCtx(ctx));
|
||||
|
||||
await auth.api.changePassword({
|
||||
headers,
|
||||
|
||||
Reference in New Issue
Block a user