Skip to content

Commit

Permalink
overload async api in mock apis
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Aug 8, 2024
1 parent f4a5ad1 commit cc7beeb
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 145 deletions.
10 changes: 8 additions & 2 deletions frontend/app/package-lock.json

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

68 changes: 35 additions & 33 deletions frontend/app/src/api/mock/MockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,70 @@ export class MockApi {
mockApiSales: MockApiSales = new MockApiSales()
mockApiProducers: MockApiProducers = new MockApiProducers()

createBeefProduction(beefProduction, callback) {
callback()
createBeefProduction() {
}

getProductions(options, callback) {
callback(undefined, this.mockApiProductions.getProductions())
getProductions() {
return this.mockApiProductions.getProductions()
}

getProductionPercentageSold(options, callback) {
callback(undefined, this.mockApiProductions.getProductionPercentageSold)
getProductionPercentageSold() {
return this.mockApiProductions.getProductionPercentageSold()
}

getBeefProduction(id, callback) {
let mockApi = this
callback(undefined, mockApi.mockApiProductions.getBeefProduction())
getBeefProduction() {
return this.mockApiProductions.getBeefProduction()
}

getPackageTemplates(callback) {
callback(undefined, this.mockApiProductions.getPackageTemplates())
getPackageTemplates() {
return this.mockApiProductions.getPackageTemplates()
}

getAddresses(callback) {
callback(undefined, this.mockApiAddresses.getAddresses())
getAddresses() {
return this.mockApiAddresses.getAddresses()
}

createCustomer(customer, callback){
callback(undefined, this.mockApiCustomers.createCustomer(customer))
createCustomer(customer){
return this.mockApiCustomers.createCustomer(customer)
}

getCustomer(options, callback){
callback(undefined, this.mockApiCustomers.getCustomer())
getCustomer(){
return this.mockApiCustomers.getCustomer()
}

getProducerSales(options, callback) {
callback(undefined, this.mockApiProducers.getProducerSales())
getProducerSales() {
return this.mockApiProducers.getProducerSales()
}

getProducerCustomers(options, callback) {
callback(undefined, this.mockApiProducers.getCustomers())
getProducerCustomers() {
return this.mockApiProducers.getCustomers()
}

getSales(callback) {
callback(undefined, this.mockApiSales.getSales())
getSales() {
return this.mockApiSales.getSales()
}

getSaleOrders(options, callback) {
callback(undefined, this.mockApiSales.getSaleOrders())
getSale() {
return this.mockApiSales.getSale()
}

getSaleProductions(options, callback) {
callback(undefined, this.mockApiSales.getSaleProductions())
getSaleOrders() {
return this.mockApiSales.getSaleOrders()
}

getOrder(option, callback) {
callback(undefined, this.mockApiSales.getOrder())
getSaleProductions() {
return this.mockApiSales.getSaleProductions()
}

createOrder(order, callback) {
callback(undefined, this.mockApiSales.createOrder(order))
getOrder() {
return this.mockApiSales.getOrder()
}

getProducer(id, callback) {
callback(undefined, this.mockApiProducers.getProducer())
createOrder(order) {
return this.mockApiSales.createOrder(order)
}

getProducer() {
return this.mockApiProducers.getProducer()
}
}
2 changes: 1 addition & 1 deletion frontend/app/src/api/mock/MockApiAddresses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Address from "@viandeendirect/api/dist/models/Address"
import {Address} from "@viandeendirect/api/dist/models/Address"

export class MockApiAddresses {
getAddresses(): Array<Address> {
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/src/api/mock/MockApiCustomers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Customer from "@viandeendirect/api/dist/models/Customer"
import {Customer} from "@viandeendirect/api/dist/models/Customer"

export class MockApiCustomers {

getCustomer() {
getCustomer(): Customer {
return {
id: 1,
user: {
Expand All @@ -15,7 +15,7 @@ export class MockApiCustomers {
//return undefined
}

createCustomer(customer: Customer) {
createCustomer(customer: Customer): Customer {
return {...customer, id: 999}
}

Expand Down
41 changes: 24 additions & 17 deletions frontend/app/src/api/mock/MockApiProducers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Customer from "@viandeendirect/api/dist/models/Customer"
import Producer from "@viandeendirect/api/dist/models/Producer"
import ProducerStatus from "@viandeendirect/api/dist/models/ProducerStatus"
import Sale from "@viandeendirect/api/dist/models/Sale"
import {Customer} from "@viandeendirect/api/dist/models/Customer"
import {Producer} from "@viandeendirect/api/dist/models/Producer"
import {Sale} from "@viandeendirect/api/dist/models/Sale"

export class MockApiProducers {

Expand All @@ -23,10 +22,10 @@ export class MockApiProducers {
}

getProducerSales(): Array<Sale> {
const sale1 = {
const sale1: Sale = {
id: 1,
deliveryStart: '2023-11-15T18:00:00',
deliveryStop: '2023-11-15T20:00:00',
deliveryStart: new Date('2023-11-15T18:00:00'),
deliveryStop: new Date('2023-11-15T20:00:00'),
deliveryAddressName: 'ESL Rémilly',
deliveryAddressLine1: '1 rue De Gaulle',
deliveryAddressLine2: undefined,
Expand All @@ -36,14 +35,15 @@ export class MockApiProducers {
{
id: 1,
productionType: 'BeefProduction',
slaughterDate: '2023-10-01T10:00:00',
slaughterDate: new Date('2023-10-01T10:00:00'),
animalLiveWeight: 450,
animalType: 'BEEF_HEIFER',
animalIdentifier: '9876'
}
],
orders: [
{
customer: {},
id: 11,
items: [
{
Expand All @@ -66,6 +66,7 @@ export class MockApiProducers {
]
},
{
customer: {},
id: 12,
items: [
{
Expand All @@ -81,10 +82,10 @@ export class MockApiProducers {
}
]
}
const sale2 = {
const sale2: Sale = {
id: 2,
deliveryStart: '2023-11-20T16:00:00',
deliveryStop: '2023-11-20T18:00:00',
deliveryStart: new Date('2023-11-20T16:00:00'),
deliveryStop: new Date('2023-11-20T18:00:00'),
deliveryAddressName: 'Place de l\'Etoile',
deliveryAddressLine1: '1 place de l\'Etoile',
deliveryAddressLine2: 'Derrière l\'Arc de Triomphe',
Expand All @@ -94,14 +95,15 @@ export class MockApiProducers {
{
id: 2,
productionType: 'BeefProduction',
slaughterDate: '2023-11-01T10:00:00',
slaughterDate: new Date('2023-11-01T10:00:00'),
animalLiveWeight: 400,
animalType: 'BEEF_COW',
animalIdentifier: '0987'
}
],
orders: [
{
customer: {},
id: 21,
items: [
{
Expand All @@ -116,6 +118,7 @@ export class MockApiProducers {
]
},
{
customer: {},
id: 22,
items: [
{
Expand All @@ -138,6 +141,7 @@ export class MockApiProducers {
]
},
{
customer: {},
id: 23,
items: [
{
Expand All @@ -153,10 +157,10 @@ export class MockApiProducers {
}
]
}
const sale3 = {
const sale3: Sale = {
id: 3,
deliveryStart: '2024-01-15T16:00:00',
deliveryStop: '2024-01-15T18:00:00',
deliveryStart: new Date('2024-01-15T16:00:00'),
deliveryStop: new Date('2024-01-15T18:00:00'),
deliveryAddressName: 'Place de l\'Etoile',
deliveryAddressLine1: '1 place de l\'Etoile',
deliveryAddressLine2: 'Derrière l\'Arc de Triomphe',
Expand All @@ -166,14 +170,15 @@ export class MockApiProducers {
{
id: 3,
productionType: 'BeefProduction',
slaughterDate: '2024-01-01T10:00:00',
slaughterDate: new Date('2024-01-01T10:00:00'),
animalLiveWeight: 400,
animalType: 'BEEF_COW',
animalIdentifier: '1234'
}
],
orders: [
{
customer: {},
id: 31,
items: [
{
Expand All @@ -188,6 +193,7 @@ export class MockApiProducers {
]
},
{
customer: {},
id: 32,
items: [
{
Expand All @@ -211,8 +217,9 @@ export class MockApiProducers {
]
},
{
customer: {},
id: 33,
items: [,
items: [
{
id: 331,
unitPrice: 80,
Expand Down
16 changes: 8 additions & 8 deletions frontend/app/src/api/mock/MockApiProductions.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import BeefProduction from "@viandeendirect/api/dist/models/BeefProduction"
import PackageTemplate from "@viandeendirect/api/dist/models/PackageTemplate"
import Production from "@viandeendirect/api/dist/models/Production"
import {BeefProduction} from "@viandeendirect/api/dist/models/BeefProduction"
import {PackageTemplate} from "@viandeendirect/api/dist/models/PackageTemplate"
import {Production} from "@viandeendirect/api/dist/models/Production"

export class MockApiProductions {

getProductions(): Array<Production> {
const production1 = {
const production1: BeefProduction = {
id: 1,
productionType: 'BeefProduction',
producer: undefined,
lots: undefined,
sales: undefined
}

const production2 = {
const production2: BeefProduction = {
id: 2,
productionType: 'BeefProduction',
producer: undefined,
Expand All @@ -27,9 +27,9 @@ export class MockApiProductions {
return {
id: 1,
animalIdentifier: '1234',
birthDate: '2022-10-01T10:00:00',
slaughterDate: '2023-10-01T10:00:00',
cuttingDate: '2024-10-01T10:00:00',
birthDate: new Date('2022-10-01T10:00:00'),
slaughterDate: new Date('2023-10-01T10:00:00'),
cuttingDate: new Date('2024-10-01T10:00:00'),
warmCarcassWeight: 450,
animalType: 'BEEF_COW',
birthFarm: 'La ferme du puis',
Expand Down
Loading

0 comments on commit cc7beeb

Please sign in to comment.