-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3128 create collection amount vs program region (#3166)
- Loading branch information
Showing
28 changed files
with
752 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...src/dataProviders/db/dataViz/amountVSProgramRegion/amountsVsProgramRegion.adapter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { | ||
AMOUNTS_VS_PROGRAM_REGION_DBOS, | ||
AMOUNTS_VS_PROGRAM_REGION_ENTITIES, | ||
} from "../../../../modules/dataViz/amountsVsProgramRegion/__fixtures__/amountsVSProgramRegion.fixture"; | ||
import AmountsVsProgramRegionAdapter from "./amountsVsProgramRegion.adapter"; | ||
describe("AmountsVsProgramRegionAdapter", () => { | ||
describe("toDbo", () => { | ||
it("should return right mapping", () => { | ||
const actual = AmountsVsProgramRegionAdapter.toDbo(AMOUNTS_VS_PROGRAM_REGION_ENTITIES[0]); | ||
const expected = { ...AMOUNTS_VS_PROGRAM_REGION_DBOS[0], _id: expect.any(Object) }; | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
.../api/src/dataProviders/db/dataViz/amountVSProgramRegion/amountsVsProgramRegion.adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ObjectId } from "mongodb"; | ||
import { AmountsVsProgramRegionDbo } from "../../../../modules/dataViz/amountsVsProgramRegion/entitiyAndDbo/amountsVsProgramRegion.dbo"; | ||
import AmountsVsProgramRegionEntity from "../../../../modules/dataViz/amountsVsProgramRegion/entitiyAndDbo/amountsVsProgramRegion.entity"; | ||
|
||
export default class AmountsVsProgramRegionAdapter { | ||
static toDbo(entity: AmountsVsProgramRegionEntity): AmountsVsProgramRegionDbo { | ||
return { | ||
_id: new ObjectId(), | ||
...entity, | ||
}; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...ges/api/src/dataProviders/db/dataViz/amountVSProgramRegion/amountsVsProgramRegion.port.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { AmountsVsProgramRegionDbo } from "../../../../modules/dataViz/amountsVsProgramRegion/entitiyAndDbo/amountsVsProgramRegion.dbo"; | ||
import AmountsVsProgramRegionEntity from "../../../../modules/dataViz/amountsVsProgramRegion/entitiyAndDbo/amountsVsProgramRegion.entity"; | ||
import MongoPort from "../../../../shared/MongoPort"; | ||
import AmountsVsProgramRegionAdapter from "./amountsVsProgramRegion.adapter"; | ||
|
||
export class AmountsVsProgramRegionPort extends MongoPort<AmountsVsProgramRegionDbo> { | ||
collectionName = "dv--montant-programme-region"; | ||
|
||
public async createIndexes(): Promise<void> { | ||
await this.collection.createIndex({ regionAttachementComptable: 1 }); | ||
await this.collection.createIndex({ programme: 1 }); | ||
await this.collection.createIndex({ exerciceBudgetaire: 1 }); | ||
await this.collection.createIndex( | ||
{ regionAttachementComptable: 1, programme: 1, exerciceBudgetaire: 1 }, | ||
{ unique: true }, | ||
); | ||
} | ||
|
||
public async hasBeenInitialized() { | ||
const dbo = await this.collection.findOne({}); | ||
return !!dbo; | ||
} | ||
|
||
public insertOne(entity: AmountsVsProgramRegionEntity) { | ||
return this.collection.insertOne(AmountsVsProgramRegionAdapter.toDbo(entity)); | ||
} | ||
|
||
public upsertOne(entity: AmountsVsProgramRegionEntity) { | ||
const updateDbo = AmountsVsProgramRegionAdapter.toDbo(entity); | ||
const { _id, ...DboWithoutId } = updateDbo; | ||
return this.collection.updateOne( | ||
{ | ||
regionAttachementComptable: updateDbo.regionAttachementComptable, | ||
programme: updateDbo.programme, | ||
exerciceBudgetaire: updateDbo.exerciceBudgetaire, | ||
}, | ||
{ $set: DboWithoutId }, | ||
{ upsert: true }, | ||
); | ||
} | ||
|
||
public insertMany(entities: AmountsVsProgramRegionEntity[]) { | ||
return this.collection.insertMany( | ||
entities.map(entity => AmountsVsProgramRegionAdapter.toDbo(entity), { ordered: false }), | ||
); | ||
} | ||
|
||
public upsertMany(entities: AmountsVsProgramRegionEntity[]) { | ||
const bulkWriteArray = entities.map(entity => { | ||
const updateDbo = AmountsVsProgramRegionAdapter.toDbo(entity); | ||
const { _id, ...DboWithoutId } = updateDbo; | ||
return { | ||
updateOne: { | ||
filter: { | ||
regionAttachementComptable: updateDbo.regionAttachementComptable, | ||
programme: updateDbo.programme, | ||
exerciceBudgetaire: updateDbo.exerciceBudgetaire, | ||
}, | ||
update: { $set: DboWithoutId }, | ||
upsert: true, | ||
}, | ||
}; | ||
}); | ||
|
||
return this.collection.bulkWrite(bulkWriteArray, { ordered: false }); | ||
} | ||
|
||
public async findAll() { | ||
return (await this.collection.find({})).toArray(); | ||
} | ||
|
||
public async deleteAll() { | ||
await this.collection.deleteMany({}); | ||
} | ||
} | ||
|
||
const amountsVsProgrammeRegionPort = new AmountsVsProgramRegionPort(); | ||
export default amountsVsProgrammeRegionPort; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
packages/api/src/dataProviders/db/providers/chorus/chorus.line.port.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/api/src/interfaces/cli/AmountsVsProgramRegion.cli.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CliStaticInterface } from "../../@types"; | ||
import { StaticImplements } from "../../decorators/staticImplements.decorator"; | ||
import amountsVsProgramRegionService from "../../modules/dataViz/amountsVsProgramRegion/amountsVsProgramRegion.service"; | ||
import CliController from "../../shared/CliController"; | ||
|
||
@StaticImplements<CliStaticInterface>() | ||
export default class AmountsVsProgramRegionCli extends CliController { | ||
static cmdName = "amounts-vs-program-region"; | ||
|
||
// should only be used once, then sync with resyncExercise | ||
async init() { | ||
if (await amountsVsProgramRegionService.isCollectionInitialized()) | ||
throw new Error("DB already initialized, used resyncExercice instead"); | ||
|
||
this.logger.logIC("Create all amounts vs program region collection"); | ||
return amountsVsProgramRegionService.init(); | ||
} | ||
|
||
resyncExercice(exerciceBudgetaire: number) { | ||
this.logger.logIC(`Resync amounts vs program region collection for exercice ${exerciceBudgetaire}`); | ||
return amountsVsProgramRegionService.updateCollection(exerciceBudgetaire); | ||
} | ||
} |
Oops, something went wrong.