-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
81 changed files
with
1,911 additions
and
9,800 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,4 @@ | ||
|
||
<p align="center"> | ||
<h1 align="center"> RoadmanJS Wallet - a very wallet </h1> | ||
<h1 align="center"> RoadmanJS Notification </h1> | ||
</p> | ||
|
||
<div align="center"> | ||
<img src="./docs/wallet.jpg" width="300" /> | ||
</div> | ||
|
||
|
||
|
||
## A Roadman for wallet that supports, coinbase, stripe, nowpayments .e.t.c ... | ||
|
||
env | ||
|
||
```sh | ||
|
||
# to enable stripe | ||
STRIPE_PAYMENT_DESC=mycompany | ||
STRIPE_SECRET=xxxxxx | ||
STRIPE_ENDPOINT_SECRET=xxxxxx | ||
|
||
# to enable nowpayments for crypto | ||
NOWPAYMENTS_KEY= | ||
NOWPAYMENTS_SECRET_IPN=xxxxx # for verifying the webhooks | ||
NOWPAYMENTS_CALLBACK_URL=xxxxxx # for webhooks | ||
``` | ||
|
||
How to use | ||
|
||
```ts | ||
import roadman from "roadman"; | ||
import { stripeRoadman, nowPaymentsRoadman, getWalletResolvers, getNowPaymentsResolvers} from "@roadmanjs/wallet" | ||
|
||
roadman({ | ||
roadmen: [stripeRoadman, nowPaymentsRoadman], | ||
resolvers: [...myresolvers, ...getWalletResolvers(), ...getNowPaymentsResolvers()] | ||
}); | ||
``` |
Binary file not shown.
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,100 @@ | ||
// createBadgeByModel {owner, model} | ||
// updateBadgeCount {id or owner + model, count+-} | ||
|
||
import {Badge, BadgeModel} from './Badge.model'; | ||
|
||
import {CouchbaseConnection} from 'couchset'; | ||
import {awaitTo} from 'couchset/dist/utils'; | ||
import {isEmpty} from 'lodash'; | ||
|
||
export const createBadgeByModel = async ( | ||
owner: string, | ||
model: string = owner | ||
): Promise<Badge | null> => { | ||
try { | ||
const [, existingBadge] = await awaitTo( | ||
BadgeModel.pagination({ | ||
where: { | ||
owner, | ||
model, | ||
}, | ||
}) | ||
); | ||
|
||
if (isEmpty(existingBadge) || !existingBadge) { | ||
return await BadgeModel.create({ | ||
owner, | ||
model, | ||
count: 0, | ||
}); | ||
} | ||
return existingBadge && existingBadge[0]; | ||
} catch (error) { | ||
console.log('error creating badge', error); | ||
return null; | ||
} | ||
}; | ||
|
||
export const getBadges = async (owner: string, models: string[]): Promise<Badge[] | null> => { | ||
try { | ||
const bucket = CouchbaseConnection.Instance.bucketName; | ||
|
||
const query = ` | ||
SELECT * | ||
FROM \`${bucket}\` badge | ||
WHERE badge._type = "${Badge.name}" | ||
AND badge.owner = "${owner}" | ||
AND badge.model in ${JSON.stringify(models)}; | ||
`; | ||
|
||
const [errorFetching, data] = await awaitTo( | ||
BadgeModel.customQuery({ | ||
query: query, | ||
params: [owner, models], | ||
limit: 1000, | ||
}) | ||
); | ||
|
||
if (errorFetching) { | ||
throw errorFetching; | ||
} | ||
|
||
const [existingBadge = []] = data; | ||
/** | ||
const createNewBadges = models.map(async (model) => { | ||
return await createBadgeByModel(owner, model); | ||
} | ||
const badges = await Promise.all(createNewBadges); | ||
*/ | ||
|
||
if (isEmpty(existingBadge) || !existingBadge) { | ||
return null; | ||
} | ||
|
||
return existingBadge.map((x: any) => BadgeModel.parse(x.badge)); | ||
} catch (error) { | ||
console.log('error getting badge', error); | ||
return null; | ||
} | ||
}; | ||
|
||
export const updateBadgeCount = async (owner: string, model: string, count: number) => { | ||
try { | ||
// find badge | ||
const [errorBadge, badge] = await awaitTo(createBadgeByModel(owner, model)); | ||
if (errorBadge) { | ||
throw errorBadge; | ||
} | ||
if (!badge || isEmpty(badge)) { | ||
throw new Error('error updating badge count'); | ||
} | ||
const currentCount = badge.count || 0; | ||
const newBadgeCount = currentCount + count; | ||
badge.count = newBadgeCount < 0 ? 0 : newBadgeCount; | ||
|
||
return await BadgeModel.updateById(badge.id, badge); | ||
} catch (error) { | ||
console.log('error updating badge count', error); | ||
return null; | ||
} | ||
}; |
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,29 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import {Field, InputType, Model, ObjectType} from 'couchset'; | ||
|
||
@InputType('BadgeInput') | ||
@ObjectType() | ||
export class Badge { | ||
@Field(() => String, {nullable: true, description: 'ID of the badge'}) | ||
id = ''; | ||
|
||
@Field(() => String, {nullable: true, description: 'The owner of the account'}) | ||
owner = ''; | ||
|
||
@Field(() => String, {nullable: true, description: 'The model for this badge'}) | ||
model = ''; | ||
|
||
@Field(() => Number, {nullable: true, description: 'Counts'}) | ||
count = 0; | ||
} | ||
|
||
export const BadgeModel = new Model(Badge.name, {graphqlType: Badge}); | ||
|
||
// automatic | ||
|
||
export const { | ||
resolver: BadgeDefaultResolver, // there's going to be other custom resolvers | ||
pagination: BadgePagination, | ||
client: BadgeClient, | ||
modelKeys: BadgeModelKeys, | ||
} = BadgeModel.automate(); |
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,30 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import {Resolver, Query, Arg, UseMiddleware, Ctx} from 'couchset'; | ||
import {log} from 'roadman'; | ||
import {Badge} from './Badge.model'; | ||
import {getBadges} from './Badge.methods'; | ||
import {ContextType, isAuth} from '@roadmanjs/auth'; | ||
import _get from 'lodash/get'; | ||
import {isEmpty} from 'lodash'; | ||
|
||
@Resolver() | ||
export class BadgeResolver { | ||
@Query(() => [Badge]) | ||
@UseMiddleware(isAuth) | ||
async getBadges( | ||
@Ctx() ctx: ContextType, | ||
@Arg('models', () => [String], {nullable: false}) models: string[] | ||
): Promise<Badge[] | null> { | ||
try { | ||
const owner = _get(ctx, 'payload.userId', ''); | ||
const badges = await getBadges(owner, models); | ||
if (!badges || isEmpty(badges)) { | ||
throw new Error('not found'); | ||
} | ||
return badges; | ||
} catch (error) { | ||
log('error getting Ad category', error); | ||
return null; | ||
} | ||
} | ||
} |
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 @@ | ||
export * from './Badge.model'; |
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 |
---|---|---|
@@ -1,9 +1,2 @@ | ||
export * from './transaction.fragment'; | ||
export * from './wallet.fragment'; | ||
export * from './wallet.query'; | ||
export * from './wallet.mutation'; | ||
export * from './transaction.query'; | ||
export * from './nowpayments.fragment'; | ||
export * from './nowpayments.query'; | ||
export * from './nowpayments.mutation'; | ||
export * from './btcpayserver.query'; | ||
export * from './notification.fragment'; | ||
export * from './notification.query'; |
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,13 @@ | ||
import gql from 'graphql-tag'; | ||
export const NotificationFragment = gql` | ||
fragment NotificationFragment on Notification { | ||
id | ||
owner | ||
createdAt | ||
updatedAt | ||
message | ||
read | ||
source | ||
sourceId | ||
} | ||
`; |
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,49 @@ | ||
import gql from 'graphql-tag'; | ||
|
||
import {NotificationFragment} from './notification.fragment'; | ||
|
||
export const GET_BADGES = gql` | ||
query GetBadges($models: [String!]!) { | ||
data: getBadges(models: $models) { | ||
id | ||
model | ||
count | ||
} | ||
} | ||
`; | ||
|
||
export const GET_NOTIFICATIONS = gql` | ||
query GetNotifications( | ||
$read: Boolean | ||
$filter: String | ||
$sort: String | ||
$before: DateTime | ||
$after: DateTime | ||
$limit: Float | ||
) { | ||
data: notifications( | ||
read: $read | ||
filter: $filter | ||
sort: $sort | ||
before: $before | ||
after: $after | ||
limit: $limit | ||
) { | ||
items { | ||
...NotificationFragment | ||
} | ||
hasNext | ||
params | ||
} | ||
} | ||
${NotificationFragment} | ||
`; | ||
|
||
export const READ_NOTIFICATIONS = gql` | ||
query ReadNotification($id: String, $before: DateTime, $limit: Float) { | ||
data: readNotifications(id: $id, before: $before, limit: $limit) { | ||
...NotificationFragment | ||
} | ||
} | ||
${NotificationFragment} | ||
`; |
Oops, something went wrong.