-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Frantz Kati
committed
Dec 9, 2020
1 parent
81bafb3
commit 962827b
Showing
37 changed files
with
270,361 additions
and
857 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { text, resource, hasOne } = require('@tensei/core') | ||
|
||
const Editor = resource('Editor').fields([ | ||
text('Full name').searchable().rules('required'), | ||
hasOne('Post'), | ||
hasOne('Comment'), | ||
]) | ||
|
||
module.exports = Editor |
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,99 @@ | ||
require('dotenv').config() | ||
const { auth } = require('@tensei/auth') | ||
const { media } = require('@tensei/media') | ||
const { graphql } = require('@tensei/graphql') | ||
const { tensei, resource, text, textarea, belongsTo, bigInteger, hasMany, plugin } = require('@tensei/core') | ||
|
||
tensei() | ||
.plugins([ | ||
auth() | ||
.rolesAndPermissions() | ||
.setup(({ user }) => { | ||
user.fields([ | ||
hasMany('Discussion'), | ||
hasMany('Comment'), | ||
belongsTo('Tenant') | ||
.rules('required') | ||
]) | ||
}) | ||
.social('github', { | ||
key: process.env.GITHUB_KEY, | ||
secret: process.env.GITHUB_SECRET, | ||
scope: ['user', 'user:email'], | ||
}) | ||
.plugin(), | ||
media() | ||
.plugin(), | ||
graphql() | ||
.plugin(), | ||
plugin('Authorize discussions') | ||
.boot(({ graphQlQueries }) => { | ||
const insert_discussion = graphQlQueries.find(query => query.config.path === 'insert_discussion') | ||
|
||
insert_discussion.authorize(async ({ body, manager, user }) => { | ||
await manager.populate([user], 'tenant') | ||
|
||
if (! body.object.user || ! body.object.tenant) { | ||
return false | ||
} | ||
|
||
if (body.object.user.toString() !== user.id.toString()) return false | ||
|
||
if (body.object.tenant.toString() !== user.tenant.id) return false | ||
|
||
return true | ||
}) | ||
}), | ||
]) | ||
.resources([ | ||
resource('Tenant') | ||
.fields([ | ||
text('Name') | ||
.rules('required', 'unique:name'), | ||
text('Slug') | ||
.rules('required', 'unique:slug') | ||
]), | ||
resource('Reaction') | ||
.fields([ | ||
text('Name') | ||
]), | ||
resource('Category') | ||
.fields([ | ||
text('Name') | ||
.rules('required'), | ||
text('Emoji Name') | ||
.rules('required'), | ||
hasMany('Discussion'), | ||
]), | ||
resource('Comment') | ||
.fields([ | ||
textarea('Content') | ||
.rules('required'), | ||
belongsTo('Discussion') | ||
.rules('required'), | ||
belongsTo('User') | ||
.rules('required'), | ||
hasMany('Reaction'), | ||
]), | ||
resource('Discussion') | ||
.fields([ | ||
text('Title') | ||
.searchable(), | ||
textarea('Content') | ||
.searchable(), | ||
belongsTo('User') | ||
.notNullable() | ||
.rules('required'), | ||
belongsTo('Tenant') | ||
.rules('required'), | ||
hasMany('Reaction'), | ||
bigInteger('Views') | ||
.nullable() | ||
.default(0), | ||
]) | ||
]) | ||
.db({ | ||
type: 'sqlite', | ||
dbName: 'tensei_fluxx.sqlite', | ||
}) | ||
.start() |
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
Oops, something went wrong.