Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add endpoints for organisation page [DEV-3848] #522

Merged
merged 55 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0b0b38b
Add base endpoints for Stripe integration
Feb 29, 2024
e50cece
Add swagger docs and make it as separate swagger for admin and api
Mar 1, 2024
77bb822
- Add Stripe webhook handling
Mar 9, 2024
a036a02
Add auth routes to admin
Mar 10, 2024
b44b322
Lint and format
Mar 10, 2024
d987e54
swagger changes
Mar 10, 2024
a4c28dc
Get rid of /admin/checkout and move it to /admin/subscriptions
Mar 18, 2024
39d8a42
Change endpoint in swagger
Mar 19, 2024
46baaa6
Fix swagger generation and add API routes
Mar 20, 2024
769b520
Fix swagger request body for subscription update
Mar 20, 2024
d39e55f
Fix stripeSync function
Mar 20, 2024
4fcd102
Get permissions from the M2M token
Mar 23, 2024
b985ec5
Sync updated and small clean-ups
Mar 24, 2024
64ea85b
Clean-ups
Mar 24, 2024
ab0da5b
Add trial period days to subscription creation
Mar 24, 2024
71f60d3
Get also trilaing subsriptions
Mar 25, 2024
042174b
Get rd of Stripe naming
Mar 25, 2024
b366935
Small cleeanups and refactoring
Mar 26, 2024
85d0aed
Merge remote-tracking branch 'origin/develop' into DEV-3671
Mar 27, 2024
9ef7459
Make swagger changes
Mar 27, 2024
dea3a23
Add encryption/decryption to API key
Apr 1, 2024
0413eb2
Change API logic a bit and introduce API key endpoints
Apr 1, 2024
91957b6
MAkes linter happy
Apr 1, 2024
7cf813f
Merge remote-tracking branch 'origin/develop' into DEV-3793
Apr 8, 2024
3df21b2
Merge remote-tracking branch 'origin/develop' into DEV-3793
Apr 8, 2024
13be89f
Get rid of apiKeyHash
Apr 9, 2024
e0fc23e
Lint
Apr 9, 2024
a2fb347
Push swagger file
Apr 9, 2024
7b232eb
Fix required field in swagger
Apr 9, 2024
2226a48
Fix swagger date-time
Apr 9, 2024
5a4fd53
Fix name field in APIKeyCreateRequestBody
Apr 9, 2024
a4cc615
Merge remote-tracking branch 'origin/develop' into DEV-3793
Apr 11, 2024
a0a953a
Get rid of env variables and make them constants
Apr 11, 2024
1804717
Move to bcrypt and HMAC API key generating
Apr 13, 2024
f5ce736
Merge branch 'develop' into DEV-3793
Apr 13, 2024
18fa100
Add error message for Stripe account creation failure
Apr 13, 2024
0623db8
Rename module to abstract
Apr 14, 2024
f555883
Move routes to api folder
Apr 14, 2024
f41d5e5
Refactor in API guarding
Apr 15, 2024
be14478
Change response text and fix tests
Apr 16, 2024
a612f2d
Add some logs
Apr 16, 2024
29f5b6f
Some refactorings
Apr 16, 2024
5e03a89
Add an ability to update organisation (customer)
Apr 16, 2024
c11d3e3
Fix typo
Apr 16, 2024
2f103ea
Revert "Fix typo"
Apr 16, 2024
d9c0fa6
Get rid of Customer in admin names
Apr 16, 2024
c0f7c86
Remove duplicate await statement
DaevMithran Apr 17, 2024
9bf2ebc
Return back user info strategy switcher
Apr 17, 2024
622ca22
Merge branch 'DEV-3848' of github.com:cheqd/credential-service into D…
Apr 17, 2024
a40283b
Fix the user info strategy picking
Apr 17, 2024
ba87c9c
Review comments
Apr 17, 2024
4d5a414
Merge remote-tracking branch 'origin/develop' into DEV-3848
Apr 17, 2024
d3345d6
update swagger-admin.json
Apr 17, 2024
cd6ec32
npm run format
ankurdotb Apr 17, 2024
a9a2aac
Fix text of error message
ankurdotb Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ The application allows configuring the following parameters using environment va

#### Events tracking

1. `ENABLE_DATADOG`: enables sending information about events to datadog
2. `LOG_LEVEL`: specifies log level, like 'trace', 'debug', 'info', 'warn' or 'error';
1. `LOG_LEVEL`: specifies log level, like 'trace', 'debug', 'info', 'warn' or 'error';

#### Network API endpoints

Expand Down
2 changes: 0 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ ARG LOGTO_M2M_APP_SECRET
ARG LOGTO_MANAGEMENT_API
ARG LOGTO_DEFAULT_ROLE_ID
ARG LOGTO_WEBHOOK_SECRET
ARG ENABLE_DATADOG=false
ARG LOG_LEVEL=info

# API generation
Expand Down Expand Up @@ -118,7 +117,6 @@ ENV LOGTO_M2M_APP_SECRET ${LOGTO_M2M_APP_SECRET}
ENV LOGTO_MANAGEMENT_API ${LOGTO_MANAGEMENT_API}
ENV LOGTO_DEFAULT_ROLE_ID ${LOGTO_DEFAULT_ROLE_ID}
ENV LOGTO_WEBHOOK_SECRET ${LOGTO_WEBHOOK_SECRET}
ENV ENABLE_DATADOG ${ENABLE_DATADOG}
ENV LOG_LEVEL ${LOG_LEVEL}

# API generatioin
Expand Down
127 changes: 127 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { SubscriptionController } from './controllers/admin/subscriptions.js';
import { PriceController } from './controllers/admin/prices.js';
import { WebhookController } from './controllers/admin/webhook.js';
import { APIKeyController } from './controllers/admin/api-key.js';
import { OrganisationController } from './controllers/admin/organisation.js';

let swaggerOptions = {};
if (process.env.ENABLE_AUTHENTICATION === 'true') {
Expand Down Expand Up @@ -282,6 +283,14 @@ class App {

// Webhook
app.post('/admin/webhook', new WebhookController().handleWebhook);

// Customer
app.post(
'/admin/organisation/update',
OrganisationController.organisationUpdatevalidator,
new OrganisationController().update
);
app.get('/admin/organisation/get', new OrganisationController().get);
}

// 404 for all other requests
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/admin/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
APIKeyUpdateResponseBody,
APIKeyUpdateUnsuccessfulResponseBody,
APIServiceOptions,
} from '../../types/portal.js';
} from '../../types/admin.js';
import { EventTracker, eventTracker } from '../../services/track/tracker.js';
import { OperationNameEnum } from '../../types/constants.js';

Expand Down
141 changes: 141 additions & 0 deletions src/controllers/admin/organisation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import * as dotenv from 'dotenv';
import type { Request, Response } from 'express';
import { check } from 'express-validator';
import { validate } from '../validator/decorator.js';
import { CustomerService } from '../../services/api/customer.js';
import { StatusCodes } from 'http-status-codes';
import type {
AdminOrganisationGetUnsuccessfulResponseBody,
AdminOrganisationUpdateResponseBody,
AdminOrganisationUpdateUnsuccessfulResponseBody,
} from '../../types/admin.js';
import { PaymentAccountService } from '../../services/api/payment-account.js';

dotenv.config();

export class OrganisationController {
static organisationUpdatevalidator = [
check('name').optional().isString().withMessage('name should be a valid string'),
check('email').optional().isEmail().withMessage('email value should a well-formatted string'),
check('description').optional().isString().withMessage('description should be a valid string'),
];

/**
* @openapi
*
* /admin/organisation/update:
* post:
* summary: Update an organisation
* description: Update an organisation
* tags: [Organisation]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* name:
* type: string
* example: Cheqd
* email:
* type: string
* example: cheqd@example.com
* format: email
* description:
* type: string
* example: Cheqd organisation
* responses:
* 200:
* description: A successful response
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/OrganisationResponseBody'
* 400:
* $ref: '#/components/schemas/InvalidRequest'
* 401:
* $ref: '#/components/schemas/UnauthorizedError'
* 500:
* $ref: '#/components/schemas/InternalError'
* 404:
* $ref: '#/components/schemas/NotFoundError'
* */
@validate
async update(request: Request, response: Response) {
const { name, email, description } = request.body;
try {
const customer = await CustomerService.instance.update(
response.locals.customer.customerId,
name,
email,
description
);
const paymentAccount = await PaymentAccountService.instance.find({ customer: customer });

if (!customer || paymentAccount.length === 0) {
response.status(StatusCodes.NOT_FOUND).json({
error: 'Customer for updating not found',
} satisfies AdminOrganisationUpdateUnsuccessfulResponseBody);
}

return response.status(StatusCodes.OK).json({
name: customer.name,
email: customer.email,
description: customer.description,
cosmosAddress: paymentAccount[0].address as string,
} satisfies AdminOrganisationUpdateResponseBody);
} catch (error) {
return response.status(500).json({
error: `Internal error: ${(error as Error)?.message || error}`,
} satisfies AdminOrganisationUpdateUnsuccessfulResponseBody);
}
}

/**
* @openapi
*
* /admin/organisation/get:
* get:
* summary: Get an organisation
* description: Get an organisation
* tags: [Organisation]
* responses:
* 200:
* description: A successful response
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/OrganisationResponseBody'
* 400:
* $ref: '#/components/schemas/InvalidRequest'
* 401:
* $ref: '#/components/schemas/UnauthorizedError'
* 500:
* $ref: '#/components/schemas/InternalError'
* 404:
* $ref: '#/components/schemas/NotFoundError'
*/
async get(request: Request, response: Response) {
try {
const customer = response.locals.customer;
const paymentAccount = await PaymentAccountService.instance.find({ customer: response.locals.customer });

if (!customer || paymentAccount.length === 0) {
response.status(StatusCodes.NOT_FOUND).json({
error: 'Customer for current user was not found or did not setup properly. Please contact administrator.',
} satisfies AdminOrganisationGetUnsuccessfulResponseBody);
}
return response.status(StatusCodes.OK).json({
name: customer.name,
email: customer.email,
description: customer.description,
cosmosAddress: paymentAccount[0].address as string,
});
} catch (error) {
return response.status(500).json({
error: `Internal error: ${(error as Error)?.message || error}`,
} satisfies AdminOrganisationGetUnsuccessfulResponseBody);
}
}
}
27 changes: 0 additions & 27 deletions src/controllers/admin/portal-customer.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/controllers/admin/prices.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Stripe } from 'stripe';
import type { Request, Response } from 'express';
import * as dotenv from 'dotenv';
import type { PriceListResponseBody, PriceListUnsuccessfulResponseBody } from '../../types/portal.js';
import type { PriceListResponseBody, PriceListUnsuccessfulResponseBody } from '../../types/admin.js';
import { StatusCodes } from 'http-status-codes';
import { check } from '../validator/index.js';
import { validate } from '../validator/decorator.js';
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/admin/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
ProductListResponseBody,
ProductListUnsuccessfulResponseBody,
ProductWithPrices,
} from '../../types/portal.js';
} from '../../types/admin.js';
import { StatusCodes } from 'http-status-codes';
import { check } from '../validator/index.js';
import { validate } from '../validator/decorator.js';
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/admin/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
SubscriptionResumeResponseBody,
SubscriptionResumeRequestBody,
SubscriptionCancelRequestBody,
} from '../../types/portal.js';
} from '../../types/admin.js';
import { StatusCodes } from 'http-status-codes';
import { check } from '../validator/index.js';
import { SubscriptionService } from '../../services/admin/subscription.js';
Expand Down
Loading
Loading