Skip to content

Commit

Permalink
Fix build because types weren't properly imported.
Browse files Browse the repository at this point in the history
  • Loading branch information
rayoz12 committed Jul 27, 2022
1 parent fe0bac3 commit 268ad9b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN npm config set unsafe-perm true
RUN npm install -g typescript
RUN npm install -g ts-node
USER node
RUN npm install
RUN npm install --force
COPY --chown=node:node ./react-app .
RUN npm run build

Expand Down Expand Up @@ -40,4 +40,4 @@ COPY --from=reactBuilder /home/node/react/build ./public
# COPY --chown=node:node /public ./public

EXPOSE 3000
CMD [ "node", "build/main.js" ]
CMD [ "node", "build/main.js" ]
4 changes: 2 additions & 2 deletions react-app/src/components/Crops/CropTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CropTemplate, CropTemplateAPI} from "../../services/cropTemplate";
import { CropService } from "../../services/CropService";
import { Crop } from "../../services/crops";
import { getFarmer, Farmer } from "../../services/farmers";
import { Field, SubField, SubFieldCrop} from "../../../../backend/src/db/entities/field"

import { UpdateSubFieldWithCropTemplate, OrganizeReputationActions } from './helperFunctions';
import { ColonyAPI } from '../../services/colony';

Expand Down Expand Up @@ -133,7 +133,7 @@ const CropTemplateSelector = () => {
cropToUpdate.crop_template = templateForSubmission;
await cropService.updateCrop(cropToUpdate); //should check to see if the crop already has an associated template first... but can add that later
// 2. add cropTemplate and rep actions to fields: search for existing Field.Subfield[] with Crop_id and update to add cropTemplate object
const fields: Field[] = await cropTemplateAPI.getFieldsforCropId(selectedCrop);
const fields: any = await cropTemplateAPI.getFieldsforCropId(selectedCrop);
UpdateSubFieldWithCropTemplate(fields, cropTemplateAPI, selectedCrop, templateForSubmission);

// ******** UI display ********
Expand Down
13 changes: 6 additions & 7 deletions react-app/src/components/Crops/helperFunctions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Field, SubField, SubFieldCrop} from "../../../../backend/src/db/entities/field"
import { CropTemplate, CropTemplateAPI} from "../../services/cropTemplate";

const generateReputationActionMap = (template: CropTemplate) => {
Expand All @@ -10,7 +9,7 @@ const generateReputationActionMap = (template: CropTemplate) => {
}

export async function UpdateSubFieldWithCropTemplate(
fields: Field[],
fields: any,
cropTemplateAPI: CropTemplateAPI,
selectedCrop: string,
selectedCropTemplate: CropTemplate
Expand All @@ -22,9 +21,9 @@ export async function UpdateSubFieldWithCropTemplate(

// for every field found with a subfield using the crop selected, update the subfield to
// have an associated crop_template<CropTemplate> and reputationActions<string,boolean>
const subFieldsArray: SubField[] = currentField.subFields;
const subFieldsArray: any = currentField.subFields;
for(let subFieldIndex in subFieldsArray){
const subFieldCropsArray: SubFieldCrop[] = subFieldsArray[subFieldIndex].properties.crops;
const subFieldCropsArray: any = subFieldsArray[subFieldIndex].properties.crops;
for(let subFieldCropIndex in subFieldCropsArray){
if(subFieldCropsArray[subFieldCropIndex].crop._id?.toString() === selectedCrop &&
!subFieldCropsArray[subFieldCropIndex].crop_template &&
Expand All @@ -41,12 +40,12 @@ export async function UpdateSubFieldWithCropTemplate(
}
}

export function OrganizeReputationActions(field: Field): Record<string, boolean>[]{
export function OrganizeReputationActions(field: any): Record<string, boolean>[]{
let reputationMaps: Record<string, boolean>[] = []

const subFieldsArray: SubField[] = field.subFields;
const subFieldsArray: any = field.subFields;
for(let subFieldIndex in subFieldsArray){
const subFieldCropsArray: SubFieldCrop[] = subFieldsArray[subFieldIndex].properties.crops;
const subFieldCropsArray: any = subFieldsArray[subFieldIndex].properties.crops;
for(let subFieldCropIndex in subFieldCropsArray){
if(subFieldCropsArray[subFieldCropIndex].reputation_actions != null){
reputationMaps.push(subFieldCropsArray[subFieldCropIndex].reputation_actions!)
Expand Down
3 changes: 1 addition & 2 deletions react-app/src/services/colony.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import axios from 'axios';
import { Field } from '../../../backend/src/db/entities/field';

export class ColonyAPI{
APIBase = "/api/colony/";

async getReputationForFarmer(field: Field): Promise<any> {
async getReputationForFarmer(field: any): Promise<any> {
const data = await axios.post(this.APIBase, field);
console.log(data.data)
return data.data;
Expand Down
19 changes: 9 additions & 10 deletions react-app/src/services/cropTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from 'axios'
import { Crop } from './crops'
import { Field } from '../../../backend/src/db/entities/field'

export interface CropTemplate{
_id?: string,
Expand Down Expand Up @@ -34,17 +33,17 @@ export class CropTemplateAPI{

// field services

async getFieldsforCropId(cropId: string): Promise<Field[]> {
const data = await axios.get<Field[]>(this.APIBase + "getFieldsforCropId/" + cropId);
async getFieldsforCropId(cropId: string): Promise<any> {
const data = await axios.get<any>(this.APIBase + "getFieldsforCropId/" + cropId);
return data.data;
}

async updateRepActions( field: Field,
async updateRepActions( field: any,
cropId: string,
farmer: string,
actionName: string,
actionStatus: boolean): Promise<Field> {
const data = await axios.put<Field>(this.APIBase + "updateRepActions", {
actionStatus: boolean): Promise<any> {
const data = await axios.put<any>(this.APIBase + "updateRepActions", {
field : field,
cropId : cropId,
farmer : farmer,
Expand All @@ -54,13 +53,13 @@ export class CropTemplateAPI{
return data.data
}

async addCropTemplateToField(field: Field): Promise<Field> {
const data = await axios.put<Field>(this.APIBase + "addCropTemplateToField", field);
async addCropTemplateToField(field: any): Promise<any> {
const data = await axios.put<any>(this.APIBase + "addCropTemplateToField", field);
return data.data
}

async getField(fieldId: string): Promise<Field> {
const data = await axios.get<Field>(this.APIBase + "getField/" + fieldId);
async getField(fieldId: string): Promise<any> {
const data = await axios.get<any>(this.APIBase + "getField/" + fieldId);
return data.data;
}
}

0 comments on commit 268ad9b

Please sign in to comment.