From cf7e4b135d69ccad0d73dbdbfe7a1c15cd69f23c Mon Sep 17 00:00:00 2001
From: Giannis Kopanas <jkopanas@gmail.com>
Date: Wed, 20 Feb 2019 12:45:33 +0200
Subject: [PATCH] fix(seed): fix global teams script

---
 scripts/seedGlobalTeams.js | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/scripts/seedGlobalTeams.js b/scripts/seedGlobalTeams.js
index ced7a87..e94aca9 100644
--- a/scripts/seedGlobalTeams.js
+++ b/scripts/seedGlobalTeams.js
@@ -1,9 +1,13 @@
 #!/usr/bin/env node
 
 const logger = require('@pubsweet/logger')
-const { model } = require('@pubsweet/model-team')
+const {
+  editoriaDataModel: {
+    models: { Team },
+  },
+} = require('editoria-data-model')
 
-const Team = model
+console.log(Team)
 
 const makeTeam = async type => {
   const names = {
@@ -12,14 +16,17 @@ const makeTeam = async type => {
 
   logger.info(`Create ${names[type]} team`)
 
-  const team = new Team({
-    global: true,
-    members: [],
-    name: names[type],
-    teamType: type,
-  })
-
-  await team.save()
+  await Team.query().upsertGraphAndFetch(
+    {
+      global: true,
+      members: [],
+      name: names[type],
+      role: type,
+    },
+    { relate: true },
+  )
+
+  // await team.save()
   logger.info(`${names[type]} team successfully created`)
 }
 
@@ -30,9 +37,7 @@ const seed = async () => {
   try {
     const teams = await Team.findByField({ global: true })
 
-    const productionEditorTeam = teams.find(
-      t => t.teamType === 'productionEditor',
-    )
+    const productionEditorTeam = teams.find(t => t.role === 'productionEditor')
 
     if (productionEditorTeam) {
       logger.info('All global teams found, exiting...')
-- 
GitLab