From b961103bff0a6840ae7f7f254e91b079f8b8850e Mon Sep 17 00:00:00 2001
From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com>
Date: Tue, 11 Jan 2022 14:31:55 +0100
Subject: [PATCH] feat: add migration to delete price on month and year

---
 src/migrations/migration.data.ts | 88 ++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/src/migrations/migration.data.ts b/src/migrations/migration.data.ts
index 8671b69e5..d6746523a 100644
--- a/src/migrations/migration.data.ts
+++ b/src/migrations/migration.data.ts
@@ -9,6 +9,10 @@ import {
   FLUIDPRICES_DOCTYPE,
   ENEDIS_DAY_DOCTYPE,
   GRDF_DAY_DOCTYPE,
+  ENEDIS_MONTH_DOCTYPE,
+  ENEDIS_YEAR_DOCTYPE,
+  GRDF_MONTH_DOCTYPE,
+  GRDF_YEAR_DOCTYPE,
 } from 'doctypes'
 import { DataloadEntity, Profile, ProfileType, UserChallenge } from 'models'
 import { Client } from 'cozy-client'
@@ -397,4 +401,88 @@ export const migrations: Migration[] = [
       })
     },
   },
+  {
+    baseSchemaVersion: 13,
+    targetSchemaVersion: 14,
+    appVersion: '1.6.1',
+    description: 'Remove wrong price for Enedis month',
+    releaseNotes: null,
+    docTypes: ENEDIS_MONTH_DOCTYPE,
+    queryOptions: {
+      scope: 'conso',
+      tag: 'month',
+      limit: 5,
+    },
+    run: async (_client: Client, docs: any[]): Promise<DataloadEntity[]> => {
+      return docs.map(doc => {
+        if (doc.price) {
+          delete doc.price
+        }
+        return doc
+      })
+    },
+  },
+  {
+    baseSchemaVersion: 15,
+    targetSchemaVersion: 16,
+    appVersion: '1.6.1',
+    description: 'Remove wrong price for Enedis year',
+    releaseNotes: null,
+    docTypes: ENEDIS_YEAR_DOCTYPE,
+    queryOptions: {
+      scope: 'conso',
+      tag: 'year',
+      limit: 1,
+    },
+    run: async (_client: Client, docs: any[]): Promise<DataloadEntity[]> => {
+      return docs.map(doc => {
+        if (doc.price) {
+          delete doc.price
+        }
+        return doc
+      })
+    },
+  },
+  {
+    baseSchemaVersion: 17,
+    targetSchemaVersion: 18,
+    appVersion: '1.6.1',
+    description: 'Remove wrong price for GRDF month',
+    releaseNotes: null,
+    docTypes: GRDF_MONTH_DOCTYPE,
+    queryOptions: {
+      scope: 'conso',
+      tag: 'month',
+      limit: 5,
+    },
+    run: async (_client: Client, docs: any[]): Promise<DataloadEntity[]> => {
+      return docs.map(doc => {
+        if (doc.price) {
+          delete doc.price
+        }
+        return doc
+      })
+    },
+  },
+  {
+    baseSchemaVersion: 18,
+    targetSchemaVersion: 19,
+    appVersion: '1.6.1',
+    description: 'Remove wrong price for GRDF year',
+    releaseNotes: null,
+    docTypes: GRDF_YEAR_DOCTYPE,
+    queryOptions: {
+      scope: 'conso',
+      tag: 'year',
+      limit: 1,
+    },
+    run: async (_client: Client, docs: any[]): Promise<DataloadEntity[]> => {
+      return docs.map(doc => {
+        if (doc.price) {
+          delete doc.price
+        }
+        return doc
+      })
+    },
+  },
 ]
-- 
GitLab