From 58eaa81db435e4f586eb67fd18fb05cd098808a5 Mon Sep 17 00:00:00 2001 From: Leonardo Brandao Date: Thu, 4 Sep 2025 08:26:56 -0300 Subject: [PATCH 1/3] feat: batchUpdate client and property --- src/interface/model/FTTHClient.ts | 4 ++-- src/interface/model/Property.ts | 2 +- src/proxy/entities/FTTHClient.ts | 23 ++++++++++++++++++++++- src/proxy/entities/Property.ts | 17 +++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/interface/model/FTTHClient.ts b/src/interface/model/FTTHClient.ts index 2af4152..b8dc74c 100644 --- a/src/interface/model/FTTHClient.ts +++ b/src/interface/model/FTTHClient.ts @@ -3,8 +3,8 @@ import { BaseModelSchema, stringOrObjectId } from './BaseModel'; import { TagSchema } from './Tag'; enum FTTHClientStatus { - OK = 'OK', - ERROR = 'ERROR', + OK = 0, + ERROR = 1, } const FTTHClientDataSchema = z.object({ diff --git a/src/interface/model/Property.ts b/src/interface/model/Property.ts index c2c4526..eaf9d3a 100644 --- a/src/interface/model/Property.ts +++ b/src/interface/model/Property.ts @@ -81,7 +81,7 @@ const UpdatePropertyDTOSchema = PropertyDataSchema.merge(z.object({ external_id: auto_connect: z.boolean().optional(), force: z.boolean().optional(), connector: stringOrObjectId.nullish(), - port: z.number().optional() + port: z.number().optional(), }), ) .partial(); diff --git a/src/proxy/entities/FTTHClient.ts b/src/proxy/entities/FTTHClient.ts index 0ab2959..c45fe64 100644 --- a/src/proxy/entities/FTTHClient.ts +++ b/src/proxy/entities/FTTHClient.ts @@ -1,4 +1,10 @@ -import { FTTHClient, UpdateFTTHClientDTO, UpdateFTTHClientDTOSchema } from '../../interface'; +import { + ApiFilter, + ApiFilterSchema, + FTTHClient, + UpdateFTTHClientDTO, + UpdateFTTHClientDTOSchema, +} from '../../interface'; import UpdatableProxy from '../UpdatableProxy'; import Api from '../../util/Api'; @@ -17,6 +23,21 @@ class FTTHClientProxy extends UpdatableProxy { return super.updateById(id, parsedData, options); } + public async batchUpdate( + filter: ApiFilter[] | ApiFilter[][] | Array, + data: UpdateFTTHClientDTO, + options?: Parameters[0]['options'], + ): Promise { + const parsedFilter = ApiFilterSchema.parse(filter); + const parsedData = UpdateFTTHClientDTOSchema.parse(data); + + return this.apiInstance.post({ + route: `${this._route}/batch-update`, + inputData: { filter: parsedFilter, update: parsedData }, + options, + }); + } + public async deleteById(id: FTTHClient['id'], options?: Parameters[0]['options']): Promise { return this.apiInstance.delete({ route: `${this._route}/${id}`, diff --git a/src/proxy/entities/Property.ts b/src/proxy/entities/Property.ts index 78f489e..ed8884c 100644 --- a/src/proxy/entities/Property.ts +++ b/src/proxy/entities/Property.ts @@ -4,6 +4,8 @@ import { CreatePropertyDTOSchema, UpdatePropertyDTO, UpdatePropertyDTOSchema, + ApiFilter, + ApiFilterSchema, } from '../../interface'; import WritableProxy from '../WritableProxy'; @@ -20,6 +22,21 @@ class PropertyProxy extends WritableProxy, + data: UpdatePropertyDTO, + options?: Parameters[0]['options'], + ): Promise { + const parsedFilter = ApiFilterSchema.parse(filter); + const parsedData = UpdatePropertyDTOSchema.parse(data); + + return this.apiInstance.post({ + route: `${this._route}/batch-update`, + inputData: { filter: parsedFilter, data: parsedData }, + options, + }); + } + public async updateById( id: Property['id'], data: UpdatePropertyDTO, From ae25aedd6a4e904dde47e02fba1d8112e2ef8ff1 Mon Sep 17 00:00:00 2001 From: Leonardo Brandao Date: Thu, 4 Sep 2025 09:02:10 -0300 Subject: [PATCH 2/3] fix: BatchUpdateDTO for property and client --- package.json | 2 +- src/interface/model/FTTHClient.ts | 2 ++ src/interface/model/Property.ts | 2 ++ src/proxy/entities/FTTHClient.ts | 3 ++- src/proxy/entities/Property.ts | 3 ++- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 355dd62..e79c497 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ozmap/ozmap-sdk", - "version": "1.1.2", + "version": "1.1.3", "description": "Use this sdk to access ozmap plataform and connect it to your own systems. ", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/interface/model/FTTHClient.ts b/src/interface/model/FTTHClient.ts index b8dc74c..9cf8a33 100644 --- a/src/interface/model/FTTHClient.ts +++ b/src/interface/model/FTTHClient.ts @@ -48,6 +48,7 @@ const UpdateFTTHClientDTOSchema = FTTHClientDataSchema.merge(z.object({ external type FTTHClient = z.infer; type CreateFTTHClientDTO = z.infer; type UpdateFTTHClientDTO = z.infer; +type BatchUpdateFTTHClientDTO = Pick; export { FTTHClientStatus, @@ -57,4 +58,5 @@ export { CreateFTTHClientDTO, UpdateFTTHClientDTOSchema, UpdateFTTHClientDTO, + BatchUpdateFTTHClientDTO, }; diff --git a/src/interface/model/Property.ts b/src/interface/model/Property.ts index eaf9d3a..d034f64 100644 --- a/src/interface/model/Property.ts +++ b/src/interface/model/Property.ts @@ -89,6 +89,7 @@ const UpdatePropertyDTOSchema = PropertyDataSchema.merge(z.object({ external_id: type Property = z.infer; type CreatePropertyDTO = z.infer; type UpdatePropertyDTO = z.infer; +type BatchUpdatePropertyDTO = Pick; export { PropertySchema, @@ -97,4 +98,5 @@ export { CreatePropertyDTO, UpdatePropertyDTOSchema, UpdatePropertyDTO, + BatchUpdatePropertyDTO, }; diff --git a/src/proxy/entities/FTTHClient.ts b/src/proxy/entities/FTTHClient.ts index c45fe64..c1bddef 100644 --- a/src/proxy/entities/FTTHClient.ts +++ b/src/proxy/entities/FTTHClient.ts @@ -1,6 +1,7 @@ import { ApiFilter, ApiFilterSchema, + BatchUpdateFTTHClientDTO, FTTHClient, UpdateFTTHClientDTO, UpdateFTTHClientDTOSchema, @@ -25,7 +26,7 @@ class FTTHClientProxy extends UpdatableProxy { public async batchUpdate( filter: ApiFilter[] | ApiFilter[][] | Array, - data: UpdateFTTHClientDTO, + data: BatchUpdateFTTHClientDTO, options?: Parameters[0]['options'], ): Promise { const parsedFilter = ApiFilterSchema.parse(filter); diff --git a/src/proxy/entities/Property.ts b/src/proxy/entities/Property.ts index ed8884c..7710df9 100644 --- a/src/proxy/entities/Property.ts +++ b/src/proxy/entities/Property.ts @@ -6,6 +6,7 @@ import { UpdatePropertyDTOSchema, ApiFilter, ApiFilterSchema, + BatchUpdatePropertyDTO, } from '../../interface'; import WritableProxy from '../WritableProxy'; @@ -24,7 +25,7 @@ class PropertyProxy extends WritableProxy, - data: UpdatePropertyDTO, + data: BatchUpdatePropertyDTO, options?: Parameters[0]['options'], ): Promise { const parsedFilter = ApiFilterSchema.parse(filter); From 23ca5fa85c16b87f634a22b2eb75db3b1187276c Mon Sep 17 00:00:00 2001 From: Leonardo Brandao Date: Thu, 4 Sep 2025 09:57:27 -0300 Subject: [PATCH 3/3] fix: update BatchUpdateDTO schemas for FTTHClient and Property --- src/interface/model/FTTHClient.ts | 8 +++++++- src/interface/model/Property.ts | 7 ++++++- src/proxy/entities/FTTHClient.ts | 3 ++- src/proxy/entities/Property.ts | 3 ++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/interface/model/FTTHClient.ts b/src/interface/model/FTTHClient.ts index 9cf8a33..7745103 100644 --- a/src/interface/model/FTTHClient.ts +++ b/src/interface/model/FTTHClient.ts @@ -44,11 +44,16 @@ const CreateFTTHClientDTOSchema = FTTHClientDataSchema.partial({ cpe: true, }).merge(z.object({ external_id: z.any().optional() })); const UpdateFTTHClientDTOSchema = FTTHClientDataSchema.merge(z.object({ external_id: z.any().optional() })).partial(); +const BatchUpdateFTTHClientDTOSchema = FTTHClientDataSchema.pick({ + certified: true, + implanted: true, + status: true, +}); type FTTHClient = z.infer; type CreateFTTHClientDTO = z.infer; type UpdateFTTHClientDTO = z.infer; -type BatchUpdateFTTHClientDTO = Pick; +type BatchUpdateFTTHClientDTO = z.infer; export { FTTHClientStatus, @@ -58,5 +63,6 @@ export { CreateFTTHClientDTO, UpdateFTTHClientDTOSchema, UpdateFTTHClientDTO, + BatchUpdateFTTHClientDTOSchema, BatchUpdateFTTHClientDTO, }; diff --git a/src/interface/model/Property.ts b/src/interface/model/Property.ts index d034f64..4fcd01f 100644 --- a/src/interface/model/Property.ts +++ b/src/interface/model/Property.ts @@ -86,10 +86,14 @@ const UpdatePropertyDTOSchema = PropertyDataSchema.merge(z.object({ external_id: ) .partial(); +const BatchUpdatePropertyDTOSchema = PropertyDataSchema.pick({ + potencyRead: true, +}); + type Property = z.infer; type CreatePropertyDTO = z.infer; type UpdatePropertyDTO = z.infer; -type BatchUpdatePropertyDTO = Pick; +type BatchUpdatePropertyDTO = z.infer; export { PropertySchema, @@ -98,5 +102,6 @@ export { CreatePropertyDTO, UpdatePropertyDTOSchema, UpdatePropertyDTO, + BatchUpdatePropertyDTOSchema, BatchUpdatePropertyDTO, }; diff --git a/src/proxy/entities/FTTHClient.ts b/src/proxy/entities/FTTHClient.ts index c1bddef..5479aa6 100644 --- a/src/proxy/entities/FTTHClient.ts +++ b/src/proxy/entities/FTTHClient.ts @@ -2,6 +2,7 @@ import { ApiFilter, ApiFilterSchema, BatchUpdateFTTHClientDTO, + BatchUpdateFTTHClientDTOSchema, FTTHClient, UpdateFTTHClientDTO, UpdateFTTHClientDTOSchema, @@ -30,7 +31,7 @@ class FTTHClientProxy extends UpdatableProxy { options?: Parameters[0]['options'], ): Promise { const parsedFilter = ApiFilterSchema.parse(filter); - const parsedData = UpdateFTTHClientDTOSchema.parse(data); + const parsedData = BatchUpdateFTTHClientDTOSchema.parse(data); return this.apiInstance.post({ route: `${this._route}/batch-update`, diff --git a/src/proxy/entities/Property.ts b/src/proxy/entities/Property.ts index 7710df9..4fd5767 100644 --- a/src/proxy/entities/Property.ts +++ b/src/proxy/entities/Property.ts @@ -7,6 +7,7 @@ import { ApiFilter, ApiFilterSchema, BatchUpdatePropertyDTO, + BatchUpdatePropertyDTOSchema, } from '../../interface'; import WritableProxy from '../WritableProxy'; @@ -29,7 +30,7 @@ class PropertyProxy extends WritableProxy[0]['options'], ): Promise { const parsedFilter = ApiFilterSchema.parse(filter); - const parsedData = UpdatePropertyDTOSchema.parse(data); + const parsedData = BatchUpdatePropertyDTOSchema.parse(data); return this.apiInstance.post({ route: `${this._route}/batch-update`,