Skip to content

Commit 1bd62c2

Browse files
committed
Refactor service schema interfaces and update type definitions for improved type safety
1 parent 02e3ef8 commit 1bd62c2

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

src/_common/abstracts/interfaces/service.schema.interface.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Document,
33
FilterQuery,
44
ModifyResult,
5+
MongooseBaseQueryOptions,
56
ProjectionType,
67
Query,
78
QueryOptions,
@@ -10,6 +11,7 @@ import {
1011
UpdateQuery,
1112
} from 'mongoose';
1213
import { AbstractSchema } from '../schemas/abstract.schema';
14+
import mongodb from 'mongodb';
1315

1416
export interface ServiceSchemaInterface {
1517
/* eslint-disable */
@@ -19,7 +21,7 @@ export interface ServiceSchemaInterface {
1921
options?: QueryOptions<T> | null | undefined,
2022
): Promise<Query<Array<T>, T, any, T>[]>
2123

22-
count<T extends AbstractSchema | Document>(filter?: FilterQuery<T>, options?: QueryOptions<T> | null | undefined): Promise<number>
24+
count<T extends AbstractSchema | Document>(filter?: FilterQuery<T>, options?: (mongodb.CountOptions & MongooseBaseQueryOptions<T>) | null): Promise<number>
2325

2426
findAndCount<T extends AbstractSchema | Document>(
2527
filter?: FilterQuery<T>,

src/_common/abstracts/schemas/abstract.schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Types, Document } from 'mongoose';
33
import { MetadataPart, MetadataPartSchema } from '~/_common/abstracts/schemas/parts/metadata.part.schema';
44

55
export abstract class AbstractSchema extends Document {
6-
public readonly _id?: Types.ObjectId | any // eslint-disable-line
6+
public readonly _id: Types.ObjectId | any // eslint-disable-line
77

88
@Prop({ type: MetadataPartSchema })
99
public metadata?: MetadataPart;

src/core/filestorage/filestorage.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ export class FilestorageService extends AbstractServiceSchema {
9898
return {
9999
...data.toObject(),
100100
_exists: storageRequest.exists,
101-
}
101+
} as any
102102
}
103-
return data.toObject()
103+
return data.toObject() as any
104104
}
105105

106106
public async findByIdWithRawData<T extends Filestorage | Document>(
@@ -128,9 +128,9 @@ export class FilestorageService extends AbstractServiceSchema {
128128
return {
129129
...data.toObject(),
130130
_exists: storageRequest.exists,
131-
}
131+
} as any
132132
}
133-
return data.toObject()
133+
return data.toObject() as any
134134
}
135135

136136
public async findOneWithRawData<T extends Filestorage | Document>(
@@ -183,7 +183,7 @@ export class FilestorageService extends AbstractServiceSchema {
183183
) {
184184
let stored: Document<any, any, Filestorage> & Filestorage
185185
try {
186-
stored = await this.findOne<Filestorage>(filter, options)
186+
stored = (await this.findOne<Filestorage>(filter, options)) as any
187187
} catch (e) {
188188
if (e.status !== HttpStatus.NOT_FOUND) throw e
189189
}

src/core/keyrings/keyrings.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { Model, SaveOptions, Document } from 'mongoose';
55
import { AbstractServiceSchema } from '~/_common/abstracts/abstract.service.schema';
66
import { KeyringsCreateDto } from './_dto/keyrings.dto';
77
import { randomBytes } from 'node:crypto';
8+
import { AbstractSchema } from '~/_common/abstracts/schemas/abstract.schema';
89

910
@Injectable()
1011
export class KeyringsService extends AbstractServiceSchema {
1112
constructor(@InjectModel(Keyrings.name) protected _model: Model<Keyrings>) {
1213
super();
1314
}
1415

15-
public async create<T extends Keyrings | Document>(
16+
public async create<T extends AbstractSchema | Document>(
1617
data?: KeyringsCreateDto,
1718
options?: SaveOptions,
1819
): Promise<Document<T, any, T>> {

src/management/identities/_dto/_parts/additionalFields.dto.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ export class additionalFieldsPartDto {
1111
public objectClasses: string[] = [];
1212

1313
@ApiProperty({
14-
type: 'object',
14+
type: Object,
1515
name: 'attributes',
1616
})
1717
@IsOptional()
1818
public attributes: { [key: string]: any } = {};
1919

2020
@ApiProperty({
21-
type: 'object',
21+
type: Object,
2222
name: 'validations',
2323
})
2424
public validations?: { [key: string]: { [key: string]: string } };

src/management/identities/identities-crud.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class IdentitiesCrudController extends AbstractController {
8686
const data = await this._service.create<Identities>(body);
8787
// If the state is TO_COMPLETE, the identity is created but additional fields are missing or invalid
8888
// Else the state is TO_VALIDATE, we return a 201 status code
89-
if ((data as Identities).state === IdentityState.TO_COMPLETE) {
89+
if (data.toObject().state === IdentityState.TO_COMPLETE) {
9090
statusCode = HttpStatus.ACCEPTED;
9191
message = 'Identitée créée avec succès, mais des champs additionnels sont manquants ou invalides.';
9292
}
@@ -234,7 +234,7 @@ export class IdentitiesCrudController extends AbstractController {
234234
public async updateStateMany(
235235
@Res() res: Response,
236236
@Body()
237-
body: {
237+
body: {
238238
originState: IdentityState;
239239
targetState: IdentityState;
240240
ids: Types.ObjectId[];

0 commit comments

Comments
 (0)