Merge pull request #85 from Irev-Dev/setup-seed-data
Add seed data to seed.js
This commit was merged in pull request #85.
This commit is contained in:
@@ -27,6 +27,7 @@ yarn install
|
|||||||
Initialise the db
|
Initialise the db
|
||||||
``` terminal
|
``` terminal
|
||||||
yarn rw db up
|
yarn rw db up
|
||||||
|
yarn rw db seed
|
||||||
```
|
```
|
||||||
|
|
||||||
### Fire up dev
|
### Fire up dev
|
||||||
@@ -36,6 +37,14 @@ yarn rw dev
|
|||||||
|
|
||||||
Your browser should open automatically to `http://localhost:8910` to see the web app. Lambda functions run on `http://localhost:8911` and are also proxied to `http://localhost:8910/.redwood/functions/*`.
|
Your browser should open automatically to `http://localhost:8910` to see the web app. Lambda functions run on `http://localhost:8911` and are also proxied to `http://localhost:8910/.redwood/functions/*`.
|
||||||
|
|
||||||
|
you can sign in to the following accounts locally
|
||||||
|
|
||||||
|
localUser1@kurthutten.com: `abc123`
|
||||||
|
|
||||||
|
localUser2@kurthutten.com: `abc123`
|
||||||
|
|
||||||
|
localAdmin@kurthutten.com: `abc123`
|
||||||
|
|
||||||
You may need to register a account depending on what issue you are trying to tackle, This can be done by clicking the login button on the top right. This will open up netlify's idenitiy modal asking for the websites url, since it will notice you developing locally. Enter `https://cadhub.xyz/` than use you email, verify your email and you should be set.
|
You may need to register a account depending on what issue you are trying to tackle, This can be done by clicking the login button on the top right. This will open up netlify's idenitiy modal asking for the websites url, since it will notice you developing locally. Enter `https://cadhub.xyz/` than use you email, verify your email and you should be set.
|
||||||
(some routes are protected, but permissions is a big area that needs a lot of work in the near future, so it's in a very incomplete state atm)
|
(some routes are protected, but permissions is a big area that needs a lot of work in the near future, so it's in a very incomplete state atm)
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,98 @@ async function main() {
|
|||||||
// if (!existing.length) {
|
// if (!existing.length) {
|
||||||
// await db.user.create({ data: { name: 'Admin', email: 'admin@email.com' }})
|
// await db.user.create({ data: { name: 'Admin', email: 'admin@email.com' }})
|
||||||
// }
|
// }
|
||||||
|
const users = [
|
||||||
|
{
|
||||||
|
id: "a2b21ce1-ae57-43a2-b6a3-b6e542fd9e60",
|
||||||
|
userName: "local-user-1",
|
||||||
|
name: "local 1",
|
||||||
|
email: "localUser1@kurthutten.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "682ba807-d10e-4caf-bf28-74054e46c9ec",
|
||||||
|
userName: "local-user-2",
|
||||||
|
name: "local 2",
|
||||||
|
email: "localUser2@kurthutten.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "5cea3906-1e8e-4673-8f0d-89e6a963c096",
|
||||||
|
userName: "local-admin-2",
|
||||||
|
name: "local admin",
|
||||||
|
email: "localAdmin@kurthutten.com"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
let existing
|
||||||
|
existing = await db.user.findMany({ where: { id: users[0].id }})
|
||||||
|
if(!existing.length) {
|
||||||
|
await db.user.create({
|
||||||
|
data: users[0],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
existing = await db.user.findMany({ where: { id: users[1].id }})
|
||||||
|
if(!existing.length) {
|
||||||
|
await db.user.create({
|
||||||
|
data: users[1],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = [
|
||||||
|
{
|
||||||
|
title: 'demo-part1',
|
||||||
|
description: '# can be markdown',
|
||||||
|
mainImage: 'CadHub/kjdlgjnu0xmwksia7xox',
|
||||||
|
user: {
|
||||||
|
connect: {
|
||||||
|
id: users[0].id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'demo-part2',
|
||||||
|
description: '## [hey](www.google.com)',
|
||||||
|
user: {
|
||||||
|
connect: {
|
||||||
|
id: users[1].id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
existing = await db.part.findMany({where: { title: parts[0].title}})
|
||||||
|
if(!existing.length) {
|
||||||
|
await db.part.create({
|
||||||
|
data: parts[0],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
existing = await db.part.findMany({where: { title: parts[1].title}})
|
||||||
|
if(!existing.length) {
|
||||||
|
await db.part.create({
|
||||||
|
data: parts[1],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const aPart = await db.part.findOne({where: {
|
||||||
|
title_userId: {
|
||||||
|
title: parts[0].title,
|
||||||
|
userId: users[0].id,
|
||||||
|
}
|
||||||
|
}})
|
||||||
|
await db.comment.create({
|
||||||
|
data: {
|
||||||
|
text: "nice part, I like it",
|
||||||
|
user: {connect: { id: users[0].id}},
|
||||||
|
part: {connect: { id: aPart.id}},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await db.partReaction.create({
|
||||||
|
data: {
|
||||||
|
emote: "❤️",
|
||||||
|
user: {connect: { id: users[0].id}},
|
||||||
|
part: {connect: { id: aPart.id}},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
console.info('No data to seed. See api/prisma/seeds.js for info.')
|
console.info('No data to seed. See api/prisma/seeds.js for info.')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,4 +141,8 @@ export const requireAuth = ({ role } = {}) => {
|
|||||||
) {
|
) {
|
||||||
throw new ForbiddenError("You don't have access to do that.")
|
throw new ForbiddenError("You don't have access to do that.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(context.currentUser?.sub === '5cea3906-1e8e-4673-8f0d-89e6a963c096') {
|
||||||
|
throw new ForbiddenError("That's a local admin ONLY.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user