-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#23 | change follow create subcsription when register
- Loading branch information
Showing
43 changed files
with
712 additions
and
344 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,9 @@ | ||
export const BILLING_PRICE = { | ||
freelancer: { | ||
price: 12, | ||
permissions: ['can_invite_user', 'can_remove_user'], | ||
}, | ||
startup: { | ||
price: 24, | ||
permissions: ['can_invite_user', 'can_remove_user', 'can_set_admin_user'], | ||
}, | ||
enterprise: { | ||
price: 48, | ||
permissions: [ | ||
'can_invite_user', | ||
'can_remove_user', | ||
'can_set_admin_user', | ||
'can_create_group', | ||
], | ||
}, | ||
export const PERMISSION_PLAN = { | ||
starter: ['can_invite_user', 'can_remove_user', 'can_set_admin_user'], | ||
professional: [ | ||
'can_invite_user', | ||
'can_remove_user', | ||
'can_set_admin_user', | ||
'can_create_group', | ||
], | ||
}; |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
const TABLES = { | ||
users: 'users', | ||
userToken: 'user_token', | ||
userTokens: 'user_tokens', | ||
userPlans: 'user_plans', | ||
userPermissions: 'user_permissions', | ||
products: 'products', | ||
prices: 'prices', | ||
}; | ||
|
||
export { TABLES }; |
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,5 @@ | ||
import { AuthenticationError } from 'apollo-server-express'; | ||
import { skip } from 'graphql-resolvers'; | ||
|
||
export const isAuthenticated = (parent, args, { user }) => | ||
user && user.email ? skip : new AuthenticationError('Authentication fail'); |
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,14 @@ | ||
import { combineResolvers } from 'graphql-resolvers'; | ||
import { getUserPlan } from '~/services/user/plans-user.service'; | ||
import { isAuthenticated } from './authorization.resolver'; | ||
|
||
const resolvers = { | ||
Query: { | ||
getUserPlan: combineResolvers( | ||
isAuthenticated, | ||
(_, args, { user }) => getUserPlan(user.id), | ||
), | ||
}, | ||
}; | ||
|
||
export default resolvers; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import userResolves from './resolvers/user.resolver'; | ||
import userPlanResolves from './resolvers/user-plan.resolver'; | ||
import stripeResolves from './resolvers/stripe.resolver'; | ||
|
||
export default [userResolves, stripeResolves]; | ||
export default [userResolves, userPlanResolves, stripeResolves]; |
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,20 @@ | ||
import pkg from 'apollo-server-express'; | ||
|
||
const { gql } = pkg; | ||
|
||
export const UserPlanSchema = gql` | ||
type ResponseUserPlan { | ||
userId: Int! | ||
productId: Int! | ||
priceId: Int! | ||
name: String! | ||
amount: Float! | ||
productType: String! | ||
priceType: String! | ||
} | ||
extend type Query { | ||
getUserPlan: ResponseUserPlan! | ||
} | ||
`; |
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
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
15 changes: 0 additions & 15 deletions
15
api/migrations/20201119143905_addAvatarAndProviderToUsers.js
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
export function up(knex) { | ||
return knex.schema.createTable('products', (t) => { | ||
t.increments('id'); | ||
t.string('name').notNullable(); | ||
t.string('type').notNullable(); | ||
t.string('stripe_id').notNullable(); | ||
t.dateTime('created_at') | ||
.notNullable() | ||
.defaultTo(knex.raw('CURRENT_TIMESTAMP')); | ||
t.dateTime('updated_at') | ||
.notNullable() | ||
.defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')); | ||
t.unique('type'); | ||
}); | ||
} | ||
|
||
export function down(knex) { | ||
return knex.schema.dropTable('products'); | ||
} |
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,20 @@ | ||
export function up(knex) { | ||
return knex.schema.createTable('prices', (t) => { | ||
t.increments('id'); | ||
t.float('amount').notNullable(); | ||
t.string('type').notNullable(); | ||
t.string('stripe_id').notNullable(); | ||
t.integer('product_id').unsigned().notNullable(); | ||
t.dateTime('created_at') | ||
.notNullable() | ||
.defaultTo(knex.raw('CURRENT_TIMESTAMP')); | ||
t.dateTime('updated_at') | ||
.notNullable() | ||
.defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')); | ||
t.foreign('product_id').references('id').inTable('products'); | ||
}); | ||
} | ||
|
||
export function down(knex) { | ||
return knex.schema.dropTable('prices'); | ||
} |
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,18 @@ | ||
import database from '~/config/database.config'; | ||
import { TABLES } from '~/constants/table-name.constant'; | ||
|
||
const TABLE = TABLES.prices; | ||
|
||
export const priceColumns = { | ||
id: 'prices.id', | ||
amount: 'prices.amount', | ||
type: 'prices.type', | ||
stripeId: 'prices.stripe_id', | ||
productId: 'prices.product_id', | ||
createAt: 'prices.created_at', | ||
updatedAt: 'prices.updated_at', | ||
}; | ||
|
||
export function insertPrice(priceData = [], transaction) { | ||
return database(TABLE).insert(priceData).transacting(transaction); | ||
} |
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,47 @@ | ||
import database from '~/config/database.config'; | ||
import { TABLES } from '~/constants/table-name.constant'; | ||
import { insertPrice, priceColumns } from './prices.repository'; | ||
|
||
const TABLE = TABLES.products; | ||
|
||
export const productColumns = { | ||
id: 'products.id', | ||
name: 'products.name', | ||
type: 'products.type', | ||
stripeId: 'products.stripe_id', | ||
createAt: 'products.created_at', | ||
updatedAt: 'products.updated_at', | ||
}; | ||
|
||
export async function insertProduct(productData, priceDatas = []) { | ||
let t; | ||
try { | ||
t = await database.transaction(); | ||
const [productId] = await database(TABLE).transacting(t).insert(productData); | ||
await insertPrice(priceDatas.map((priceItem) => ({ | ||
...priceItem, | ||
product_id: productId, | ||
})), t); | ||
await t.commit(); | ||
return true; | ||
} catch (error) { | ||
if (t) t.rollback(); | ||
return false; | ||
} | ||
} | ||
|
||
export function findProductByType(type) { | ||
return database(TABLE).where({ type }).first(); | ||
} | ||
|
||
export function findProductInType(types) { | ||
return database(TABLE).whereIn('type', types); | ||
} | ||
|
||
export function findProductAndPriceByType(productType, priceType) { | ||
return database(TABLE) | ||
.join(TABLES.prices, productColumns.id, priceColumns.product_id) | ||
.select(productColumns, `${priceColumns.id} as price_id`, priceColumns.amount, `${priceColumns.type} as price_type`, `${priceColumns.stripeId} as price_stripe_id`) | ||
.where({ [productColumns.type]: productType, [priceColumns.type]: priceType }) | ||
.first(); | ||
} |
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.