Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddybi committed Mar 31, 2024
1 parent eaad78d commit e5e2151
Show file tree
Hide file tree
Showing 81 changed files with 1,911 additions and 9,800 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
'prettier/prettier': 'error',
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
Expand All @@ -34,7 +34,7 @@ module.exports = {
'import/named': 'off',
'import/namespace': 'off',
'simple-import-sort/sort': 'off',
'sort-imports': 'off',
'sort-imports': 'off'
},
settings: {},
};
37 changes: 1 addition & 36 deletions README.md
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 removed docs/wallet.jpg
Binary file not shown.
18 changes: 4 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@roadmanjs/wallet",
"version": "0.0.74",
"description": "A very Wallet",
"name": "@roadmanjs/notification",
"version": "0.0.1",
"description": "notification",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -43,11 +43,8 @@
},
"devDependencies": {
"@types/chai": "^4.2.14",
"@types/chalk": "^2.2.0",
"@types/coinbase": "^2.0.8",
"@types/debug": "^4.1.5",
"@types/dotenv": "^8.2.0",
"@types/ioredis": "^5.0.0",
"@types/lodash": "^4.14.168",
"@types/mocha": "^8.2.0",
"@types/node": "^10.0.3",
Expand Down Expand Up @@ -80,21 +77,14 @@
"typescript": ">=2.0"
},
"dependencies": {
"@nowpaymentsio/nowpayments-api-js": "^1.0.5",
"@roadmanjs/auth": "^0.0.32",
"@roadmanjs/auth-client": "^0.0.32",
"@roadmanjs/logs": "^0.0.1",
"@roadmanjs/utils": "^0.0.12",
"bull": "^4.11.3",
"chalk": "^4.1.0",
"coinbase": "^2.0.8",
"couchset": "^0.0.17",
"debug": "^4.3.1",
"dotenv": "^8.2.0",
"lodash": "^4.17.20",
"node-cron": "^3.0.2",
"reflect-metadata": "^0.1.13",
"roadman": "^0.3.12",
"stripe": "^10.17.0"
"roadman": "^0.3.12"
}
}
100 changes: 100 additions & 0 deletions src/badge/Badge.methods.ts
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;
}
};
29 changes: 29 additions & 0 deletions src/badge/Badge.model.ts
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();
30 changes: 30 additions & 0 deletions src/badge/Badge.resolver.ts
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;
}
}
}
1 change: 1 addition & 0 deletions src/badge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Badge.model';
15 changes: 0 additions & 15 deletions src/client/query/btcpayserver.query.ts

This file was deleted.

11 changes: 2 additions & 9 deletions src/client/query/index.ts
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';
13 changes: 13 additions & 0 deletions src/client/query/notification.fragment.ts
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
}
`;
49 changes: 49 additions & 0 deletions src/client/query/notification.query.ts
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}
`;
Loading

0 comments on commit e5e2151

Please sign in to comment.