Skip to content

Commit

Permalink
Merge pull request #304 from fawizzy/create_organization
Browse files Browse the repository at this point in the history
feat: API Endpoint to Create Organisation
  • Loading branch information
incredible-phoenix246 authored Jul 25, 2024
2 parents b05d298 + ffa4de5 commit fcedce9
Show file tree
Hide file tree
Showing 18 changed files with 7,709 additions and 206 deletions.
7,097 changes: 7,097 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"start": "ts-node --transpile-only src/index.ts",
"test": "jest --forceExit",
"test:email": "jest views/email/tests",
"test:organisation": "jest organisation.spec.ts",
"typeorm": "typeorm-ts-node-commonjs",
"build": "tsc",
"seed": "ts-node src/seeder.ts",
Expand Down
119 changes: 118 additions & 1 deletion src/controllers/OrgController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response } from "express";
import { Request, Response, NextFunction } from "express";
import { OrgService } from "../services/org.services";
import log from "../utils/logger";

Expand All @@ -7,6 +7,123 @@ export class OrgController {
constructor() {
this.orgService = new OrgService();
}
/**
* @swagger
* /organisation:
* post:
* summary: Create a new organisation
* description: This endpoint allows a user to create a new organisation
* tags:
* - Organisation
* operationId: createOrganisation
* requestBody:
* description: Organisation payload
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* name:
* type: string
* example: My Organisation
* description:
* type: string
* example: This is a sample organisation.
* required:
* - name
* responses:
* '201':
* description: Organisation created successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: success
* message:
* type: string
* example: Organisation created successfully
* data:
* type: object
* properties:
* id:
* type: string
* example: "1"
* name:
* type: string
* example: My Organisation
* description:
* type: string
* example: This is a sample organisation.
* createdAt:
* type: string
* format: date-time
* updatedAt:
* type: string
* format: date-time
* status_code:
* type: integer
* example: 201
* '400':
* description: Bad Request
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: error
* message:
* type: string
* example: Invalid input
* status_code:
* type: integer
* example: 400
* '500':
* description: Internal Server Error
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: error
* message:
* type: string
* example: Internal server error
* status_code:
* type: integer
* example: 500
*/
async createOrganisation(req: Request, res: Response, next: NextFunction) {
try {
const payload = req.body;
const user = req.user;
const userId = user.id;

const organisationService = new OrgService();
const newOrganisation = await organisationService.createOrganisation(
payload,
userId,
);

const respObj = {
status: "success",
message: "organisation created successfully",
data: newOrganisation,
status_code: 201,
};

return res.status(201).json(respObj);
} catch (error) {
next(error);
}
}

/**
* @swagger
Expand Down
240 changes: 120 additions & 120 deletions src/controllers/createorgController.ts
Original file line number Diff line number Diff line change
@@ -1,125 +1,125 @@
import { NextFunction, Request, Response } from "express";
import { OrganisationService } from "../services/createOrg.services";
// import { NextFunction, Request, Response } from "express";
// import { OrganisationService } from "../services/organization.service";

/**
* @swagger
* /organisation:
* post:
* summary: Create a new organisation
* description: This endpoint allows a user to create a new organisation
* tags:
* - Organisation
* operationId: createOrganisation
* requestBody:
* description: Organisation payload
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* name:
* type: string
* example: My Organisation
* description:
* type: string
* example: This is a sample organisation.
* required:
* - name
* responses:
* '201':
* description: Organisation created successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: success
* message:
* type: string
* example: Organisation created successfully
* data:
* type: object
* properties:
* id:
* type: string
* example: "1"
* name:
* type: string
* example: My Organisation
* description:
* type: string
* example: This is a sample organisation.
* createdAt:
* type: string
* format: date-time
* updatedAt:
* type: string
* format: date-time
* status_code:
* type: integer
* example: 201
* '400':
* description: Bad Request
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: error
* message:
* type: string
* example: Invalid input
* status_code:
* type: integer
* example: 400
* '500':
* description: Internal Server Error
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: error
* message:
* type: string
* example: Internal server error
* status_code:
* type: integer
* example: 500
*/
// /**
// * @swagger
// * /organisation:
// * post:
// * summary: Create a new organisation
// * description: This endpoint allows a user to create a new organisation
// * tags:
// * - Organisation
// * operationId: createOrganisation
// * requestBody:
// * description: Organisation payload
// * required: true
// * content:
// * application/json:
// * schema:
// * type: object
// * properties:
// * name:
// * type: string
// * example: My Organisation
// * description:
// * type: string
// * example: This is a sample organisation.
// * required:
// * - name
// * responses:
// * '201':
// * description: Organisation created successfully
// * content:
// * application/json:
// * schema:
// * type: object
// * properties:
// * status:
// * type: string
// * example: success
// * message:
// * type: string
// * example: Organisation created successfully
// * data:
// * type: object
// * properties:
// * id:
// * type: string
// * example: "1"
// * name:
// * type: string
// * example: My Organisation
// * description:
// * type: string
// * example: This is a sample organisation.
// * createdAt:
// * type: string
// * format: date-time
// * updatedAt:
// * type: string
// * format: date-time
// * status_code:
// * type: integer
// * example: 201
// * '400':
// * description: Bad Request
// * content:
// * application/json:
// * schema:
// * type: object
// * properties:
// * status:
// * type: string
// * example: error
// * message:
// * type: string
// * example: Invalid input
// * status_code:
// * type: integer
// * example: 400
// * '500':
// * description: Internal Server Error
// * content:
// * application/json:
// * schema:
// * type: object
// * properties:
// * status:
// * type: string
// * example: error
// * message:
// * type: string
// * example: Internal server error
// * status_code:
// * type: integer
// * example: 500
// */

export const createOrganisation = async (
req: Request,
res: Response,
next: NextFunction,
) => {
try {
const payload = req.body;
const user = req.user;
const userId = user.id;
// export const createOrganisation = async (
// req: Request,
// res: Response,
// next: NextFunction,
// ) => {
// try {
// const payload = req.body;
// const user = req.user;
// const userId = user.id;

const organisationService = new OrganisationService();
const newOrganisation = await organisationService.createOrganisation(
payload,
userId,
);
// const organisationService = new OrganisationService();
// const newOrganisation = await organisationService.createOrganisation(
// payload,
// userId,
// );

const respObj = {
status: "success",
message: "organisation created successfully",
data: newOrganisation,
status_code: 201,
};
// const respObj = {
// status: "success",
// message: "organisation created successfully",
// data: newOrganisation,
// status_code: 201,
// };

return res.status(201).json(respObj);
} catch (error) {
return next(error);
}
};
// return res.status(201).json(respObj);
// } catch (error) {
// return next(error);
// }
// };
2 changes: 1 addition & 1 deletion src/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const AppDataSource = new DataSource({
entities: ["src/models/**/*.ts"],
migrations: ["src/migrations/**/*.ts"],
migrationsTableName: "migrations",
// ssl: false,
// ssl: true,
// extra: {
// ssl: {
// rejectUnauthorized: false,
Expand Down
Loading

0 comments on commit fcedce9

Please sign in to comment.