From cca9031a57b3f9055f560d6fc915041b4f28059b Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Mon, 13 Dec 2021 16:24:03 +0100
Subject: [PATCH] fix: db init script, bad collection name for structureType

---
 scripts/init-db.js | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/scripts/init-db.js b/scripts/init-db.js
index 95cead36e..52c7ce70b 100644
--- a/scripts/init-db.js
+++ b/scripts/init-db.js
@@ -2,7 +2,7 @@
 const mongoose = require('mongoose');
 // eslint-disable-next-line @typescript-eslint/no-var-requires
 const userData = require('./data/users');
-const structuresTypesData = require('./data/structuresType');
+const structuresTypeData = require('./data/structuresType');
 const categoriesOthersData = require('./data/categoriesOthers');
 const categoriesAccompanementsData = require('./data/categoriesAccompanements');
 const categoriesFormationData = require('./data/categoriesFormation');
@@ -57,10 +57,13 @@ var usersSchema = mongoose.Schema({
   password: String,
   phone: String,
 });
-var structuresTypeSchema = mongoose.Schema({
-  name: String,
-  values: [],
-});
+var structuresTypeSchema = mongoose.Schema(
+  {
+    name: String,
+    values: [],
+  },
+  { collection: 'structuretype' }
+);
 var categoriesOthersSchema = mongoose.Schema({
   name: String,
   id: String,
@@ -144,9 +147,9 @@ mongoose.connection.dropCollection('users', async (err) => {
 });
 
 /* Create structures ref */
-mongoose.connection.dropCollection('structuretypes', async (err) => {
+mongoose.connection.dropCollection('structuretype', async (err) => {
   await handleError('structureType', err);
-  structuresType.create(structuresTypesData.data, (error) => {
+  structuresType.create(structuresTypeData.data, (error) => {
     if (error) return console.error(error);
   });
 });
@@ -166,7 +169,7 @@ mongoose.connection.dropCollection('categoriesaccompagnements', async (err) => {
 });
 
 mongoose.connection.dropCollection('categoriesformations', async (err) => {
-  await handleError('categoriesFormation', err);
+  await handleError('categoriesFormations', err);
   categoriesFormation.create(categoriesFormationData.data, (error) => {
     if (error) return console.error(error);
   });
-- 
GitLab