// import { ModelQueryBuilderContract } from '@adonisjs/lucid/types/model'; // import { LucidModel } from '@adonisjs/lucid/types/model'; import { Request, Response } from '@adonisjs/core/http'; // import BaseModel from '#app/Models/BaseModel'; // import { LucidModel } from '@adonisjs/lucid/types/model'; // import BaseModel from '#app/Models/BaseModel'; Request.macro('wantsJSON', function (this: Request) { const firstType = this.types()[0]; if (!firstType) { return false; } return firstType.includes('/json') || firstType.includes('+json'); }); declare module '@adonisjs/core/http' { interface Request { wantsJSON(): boolean; } } // By specifying this: Response in the function signature, you're explicitly stating // that 'this' within the function should be of type 'Response', which resolves the TypeScript error. Response.macro('flash', function (this: Response, key: string, message: any) { if (!this.ctx) { throw new Error('Context is not available'); } this.ctx!.session.flash(key, message); return this; }); Response.macro('toRoute', function (this: Response, route: string) { this.redirect().toRoute(route); return this; }); declare module '@adonisjs/core/http' { interface Response { flash(key: string, message: any): Response; toRoute(route: string): Response; } } // declare module '@adonisjs/lucid/orm' { // // interface ModelQueryBuilder { // // pluck(value: string, id?: string): Promise; // // } // // interface ModelQueryBuilder { // // pluck(valueColumn: string, id?: string): Promise<{ [key: string]: any }>; // // } // // interface ModelQueryBuilderContract> { // // getCount(): Promise; // // pluck(valueColumn: string, id?: string): Promise<{ [key: string]: any }>; // // } // // interface ModelQueryBuilderContract> // interface ModelQueryBuilderContract> { // // macro typescript definitions here // // whereTrue(columnName: string): this; // // whereFalse(columnName: string): this; // // any(): Promise; // // selectCount(): Promise; // // selectIds(primaryKey?: string): Promise; // // selectId(primaryKey?: string): Promise; // // selectIdOrFail(primaryKey?: string): Promise; // pluck(valueColumn: string, id?: string): Promise<{ [key: string]: any }>; // } // } // ModelQueryBuilder.macro('pluck', async function (this: ModelQueryBuilder, valueColumn: string, id?: string) : Promise<{ [key: string]: any }>{ // // let rolesPluck: PluckConfig = {}; // let rolesPluck: { [key: number]: any } = {}; // const result = await this.exec(); // result.forEach((user, index) => { // let idc; // if (!id) { // idc = index; // } else { // idc = user[id] as number; // } // const value = user[valueColumn]; // // rolesPluck[idc] = user.name; // rolesPluck[idc] = value; // }); // return rolesPluck; // });