Skip to content

Commit

Permalink
✨ Backend integration webapp
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Nov 30, 2023
1 parent 5a8faee commit 742aa61
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 137 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Post } from '@nestjs/common';
import { Body, Controller, Get, Post } from '@nestjs/common';
import { OrganisationsService } from './organisations.service';
import { LoggerService } from '../logger/logger.service';
import { CreateOrganizationDto } from './dto/create-organization.dto';
Expand All @@ -12,6 +12,11 @@ export class OrganisationsController {
this.logger.setContext(OrganisationsController.name);
}

@Get()
getProjects() {
return this.organizationsService.getOrganisations();
}

@Post('create')
createOrg(@Body() orgCreateDto: CreateOrganizationDto) {
return this.organizationsService.createOrganization(orgCreateDto);
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/@core/organisations/organisations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export class OrganisationsService {
constructor(private prisma: PrismaService, private logger: LoggerService) {
this.logger.setContext(OrganisationsService.name);
}

async getOrganisations() {
return await this.prisma.organizations.findMany();
}
async createOrganization(data: CreateOrganizationDto) {
const res = await this.prisma.organizations.create({
data: {
Expand Down
7 changes: 6 additions & 1 deletion packages/api/src/@core/projects/projects.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Post } from '@nestjs/common';
import { Body, Controller, Get, Post } from '@nestjs/common';
import { ProjectsService } from './projects.service';
import { LoggerService } from '../logger/logger.service';
import { CreateProjectDto } from './dto/create-project.dto';
Expand All @@ -12,6 +12,11 @@ export class ProjectsController {
this.logger.setContext(ProjectsController.name);
}

@Get()
getProjects() {
return this.projectsService.getProjects();
}

@Post('create')
createProject(@Body() projectCreateDto: CreateProjectDto) {
return this.projectsService.createProject(projectCreateDto);
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/@core/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export class ProjectsService {
constructor(private prisma: PrismaService, private logger: LoggerService) {
this.logger.setContext(ProjectsService.name);
}

async getProjects() {
return await this.prisma.projects.findMany();
}
async createProject(data: CreateProjectDto) {
const { id_organization, ...rest } = data;
const res = await this.prisma.projects.create({
Expand Down
44 changes: 25 additions & 19 deletions packages/webapp/src/hooks/useApiKeys.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import { HookBaseReturn } from '@/types';
import config from '@/utils/config';
import { useState, useEffect } from 'react';
import { useState } from 'react';


//TODO: import from shared type
Expand All @@ -13,31 +15,35 @@ export interface Job {
date: string;
}

const useApiKeys = () => {
export interface ApiKeysReturnType extends HookBaseReturn {
apiKeys: Job[];
fetchApiKeys: () => Promise<void>;
}

type ApiKeysReturnFunction = () => ApiKeysReturnType;


const useApiKeys: ApiKeysReturnFunction = () => {
const [apiKeys, setApiKeys] = useState<Job[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);

useEffect(() => {
async function loadApiKeys() {
try {
const response = await fetch(`${config.API_URL}/apiKeys`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
setApiKeys(data);
} catch (err) {
setError(err as Error);
} finally {
setIsLoading(false);
const fetchApiKeys = async () => {
setIsLoading(true);
try {
const response = await fetch(`${config.API_URL}/auth/api-keys`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
setApiKeys(data);
} catch (err) {
setError(err as Error);
}
setIsLoading(false);
};

loadApiKeys();
}, []);

return { apiKeys, isLoading, error };
return { apiKeys, fetchApiKeys, isLoading, error };
};

export default useApiKeys;
44 changes: 25 additions & 19 deletions packages/webapp/src/hooks/useConnections.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import { HookBaseReturn } from '@/types';
import config from '@/utils/config';
import { useState, useEffect } from 'react';
import { useState } from 'react';


//TODO: import from shared type
Expand All @@ -13,31 +15,35 @@ export interface Job {
date: string;
}

const useConnections = () => {
export interface ConnectionsReturnType extends HookBaseReturn {
connections: Job[];
fetchConnections: () => Promise<void>;
}

type ConnectionsReturnFunction = () => ConnectionsReturnType;


const useConnections: ConnectionsReturnFunction = () => {
const [connections, setConnections] = useState<Job[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);

useEffect(() => {
async function loadConnections() {
try {
const response = await fetch(`${config.API_URL}/connections`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
setConnections(data);
} catch (err) {
setError(err as Error);
} finally {
setIsLoading(false);
const fetchConnections = async () => {
setIsLoading(true);
try {
const response = await fetch(`${config.API_URL}/connections`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
setConnections(data);
} catch (err) {
setError(err as Error);
}
setIsLoading(false);
};

loadConnections();
}, []);

return { connections, isLoading, error };
return { connections, fetchConnections, isLoading, error };
};

export default useConnections;
81 changes: 61 additions & 20 deletions packages/webapp/src/hooks/useFieldMappings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HookBaseReturn } from '@/types';
import config from '@/utils/config';
import { useState, useEffect } from 'react';
import { useState } from 'react';


//TODO: import from shared type
Expand All @@ -12,32 +13,72 @@ export interface Job {
organisation: string;
date: string;
}

export interface FMReturnType extends HookBaseReturn {
mappings: Job[];
standardObjects: string[];
fetchMappings: () => Promise<void>;
fetchStandardObjects: () => Promise<void>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getMapping: (id: string) => Promise<any>;
}

type FMReturnFunction = () => FMReturnType;


const useFieldMappings = () => {
const [fieldMappings, setFieldMappings] = useState<Job[]>([]);
const [isLoading, setIsLoading] = useState(true);
const useFieldMappings: FMReturnFunction = () => {
const [mappings, setMappings] = useState<Job[]>([]);
const [standardObjects, setStandardObjects] = useState<string[]>([]);

const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<Error | null>(null);

useEffect(() => {
async function loadFieldMappings() {
try {
const response = await fetch(`${config.API_URL}/fieldMappings`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
setFieldMappings(data);
} catch (err) {
setError(err as Error);
} finally {
setIsLoading(false);
const fetchMappings = async () => {
setIsLoading(true);
try {
const response = await fetch(`${config.API_URL}/field-mapping/attribute`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
setMappings(data);
} catch (err) {
setError(err as Error);
}
setIsLoading(false);
};

loadFieldMappings();
}, []);
const fetchStandardObjects = async () => {
setIsLoading(true);
try {
const response = await fetch(`${config.API_URL}/field-mapping/entities`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
setStandardObjects(data);
} catch (err) {
setError(err as Error);
}
setIsLoading(false);
};

//TODO
const getMapping = async (id: string) => {
setIsLoading(true);
try {
const response = await fetch(`${config.API_URL}/field-mapping/${id}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
return await response.json();
} catch (err) {
setError(err as Error);
}
setIsLoading(false);
};

return { fieldMappings, isLoading, error };
return { mappings, isLoading, error, fetchMappings, standardObjects, fetchStandardObjects, getMapping };
};

export default useFieldMappings;
44 changes: 25 additions & 19 deletions packages/webapp/src/hooks/useJobs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import { HookBaseReturn } from '@/types';
import config from '@/utils/config';
import { useState, useEffect } from 'react';
import { useState } from 'react';


//TODO: import from shared type
Expand All @@ -13,31 +15,35 @@ export interface Job {
date: string;
}

const useJobs = () => {
export interface JobsReturnType extends HookBaseReturn {
jobs: Job[];
fetchJobs: () => Promise<void>;
}

type JobsReturnFunction = () => JobsReturnType;


const useJobs: JobsReturnFunction = () => {
const [jobs, setJobs] = useState<Job[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);

useEffect(() => {
async function loadJobs() {
try {
const response = await fetch(`${config.API_URL}/jobs`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
setJobs(data);
} catch (err) {
setError(err as Error);
} finally {
setIsLoading(false);
const fetchJobs = async () => {
setIsLoading(true);
try {
const response = await fetch(`${config.API_URL}/jobs`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
setJobs(data);
} catch (err) {
setError(err as Error);
}
setIsLoading(false);
};

loadJobs();
}, []);

return { jobs, isLoading, error };
return { jobs, fetchJobs, isLoading, error };
};

export default useJobs;
Loading

0 comments on commit 742aa61

Please sign in to comment.