add test for create order
This commit is contained in:
1 parent
f6065f4672
commit
b3c4131a1f
5 files changed
+107
-2
No files matched your search
@@ -5,3 +5,4 @@ export * from './service';
|
|||||||
export * from './user';
|
export * from './user';
|
||||||
export * from './api';
|
export * from './api';
|
||||||
export * from './document';
|
export * from './document';
|
||||||
|
export * from './order';
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './models';
|
||||||
|
export * from './operator';
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { IService } from '../service';
|
||||||
|
|
||||||
|
export const ORDER_STATE_PENDING = 'Pending';
|
||||||
|
export const ORDER_STATE_PAID = 'Paid';
|
||||||
|
export const ORDER_STATE_EXPIRED = 'Expired';
|
||||||
|
export const ORDER_STATE_FAILED = 'Failed';
|
||||||
|
|
||||||
|
export interface IOrder {
|
||||||
|
id?: string;
|
||||||
|
description?: string;
|
||||||
|
state?: typeof ORDER_STATE_PENDING | typeof ORDER_STATE_PAID | typeof ORDER_STATE_EXPIRED | typeof ORDER_STATE_FAILED;
|
||||||
|
price?: number;
|
||||||
|
amount?: number;
|
||||||
|
user_id?: number;
|
||||||
|
created_at?: string;
|
||||||
|
updated_at?: string;
|
||||||
|
service?: IService;
|
||||||
|
service_id?: string;
|
||||||
|
wechatpay_url?: string;
|
||||||
|
alipay_url?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IOrderListResponse {
|
||||||
|
count: number;
|
||||||
|
items: IOrder[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type IOrderDetailResponse = IOrder;
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { AxiosResponse } from 'axios';
|
||||||
|
import { httpClient } from '../instance';
|
||||||
|
import { IOrder, IOrderDetailResponse, IOrderListResponse } from './models';
|
||||||
|
|
||||||
|
class OrderService {
|
||||||
|
key = 'orders';
|
||||||
|
|
||||||
|
async getAll(): Promise<AxiosResponse<IOrderListResponse>> {
|
||||||
|
return await httpClient.get(`/${this.key}/`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(id: string): Promise<AxiosResponse<IOrderDetailResponse>> {
|
||||||
|
return await httpClient.get(`/${this.key}/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(data: IOrder): Promise<AxiosResponse<IOrderDetailResponse>> {
|
||||||
|
return await httpClient.post(`/${this.key}/`, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(id: string, data: IOrder): Promise<AxiosResponse<IOrderDetailResponse>> {
|
||||||
|
return await httpClient.put(`/${this.key}/${id}`, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(id: string): Promise<AxiosResponse<null>> {
|
||||||
|
return await httpClient.delete(`/${this.key}/${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const orderOperator = new OrderService();
|
||||||
@@ -61,10 +61,26 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
<el-dialog v-model="buying" title="Warning" width="30%" center>
|
||||||
|
<span> It should be noted that the content will not be aligned in center by default </span>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="buying = false">Cancel</el-button>
|
||||||
|
<el-button type="primary" @click="onCreateOrder()"> Confirm </el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { applicationOperator, IApplication, IApplicationListResponse, IService } from '@/operators';
|
import {
|
||||||
|
applicationOperator,
|
||||||
|
IApplication,
|
||||||
|
IApplicationListResponse,
|
||||||
|
IOrderDetailResponse,
|
||||||
|
IService,
|
||||||
|
orderOperator
|
||||||
|
} from '@/operators';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||||
import Pagination from '@/components/common/Pagination.vue';
|
import Pagination from '@/components/common/Pagination.vue';
|
||||||
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
|
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
|
||||||
@@ -75,6 +91,11 @@ interface IData {
|
|||||||
total: number | undefined;
|
total: number | undefined;
|
||||||
limit: number;
|
limit: number;
|
||||||
page: number;
|
page: number;
|
||||||
|
buying: boolean;
|
||||||
|
active: {
|
||||||
|
service: IService | undefined;
|
||||||
|
application: IApplication | undefined;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -89,7 +110,12 @@ export default defineComponent({
|
|||||||
applications: [],
|
applications: [],
|
||||||
loading: false,
|
loading: false,
|
||||||
total: undefined,
|
total: undefined,
|
||||||
|
buying: false,
|
||||||
limit: 8,
|
limit: 8,
|
||||||
|
active: {
|
||||||
|
service: undefined,
|
||||||
|
application: undefined
|
||||||
|
},
|
||||||
page: parseInt(this.$route.query.page?.toString() || '1')
|
page: parseInt(this.$route.query.page?.toString() || '1')
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -103,8 +129,24 @@ export default defineComponent({
|
|||||||
this.onFetchData();
|
this.onFetchData();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onBuyMore(service: IService) {},
|
onBuyMore(service: IService) {
|
||||||
|
this.active.service = service;
|
||||||
|
this.buying = true;
|
||||||
|
},
|
||||||
onGoDocument(service: IService) {},
|
onGoDocument(service: IService) {},
|
||||||
|
onCreateOrder() {
|
||||||
|
if (!this.active?.service?.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
orderOperator
|
||||||
|
.create({
|
||||||
|
service_id: this.active?.service?.id,
|
||||||
|
amount: 10
|
||||||
|
})
|
||||||
|
.then(({ data: data }: { data: IOrderDetailResponse }) => {
|
||||||
|
console.log('data', data);
|
||||||
|
});
|
||||||
|
},
|
||||||
onPageChange(page: number) {
|
onPageChange(page: number) {
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
name: this.$route.name?.toString(),
|
name: this.$route.name?.toString(),
|
||||||
@@ -126,6 +168,9 @@ export default defineComponent({
|
|||||||
this.applications = data.items;
|
this.applications = data.items;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.total = data.count;
|
this.total = data.count;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.loading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user