Skip to content

Commit

Permalink
Merge pull request #264 from Roger13579/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
y0000ga authored Jun 22, 2024
2 parents 6c2a534 + 2c583f1 commit 604bea8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 33 deletions.
25 changes: 13 additions & 12 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
PORT=
MONGO_DB_URL=
GOOGLE_OAUTH_CLIENT_ID=
GOOGLE_OAUTH_CLIENT_SECRET=
GOOGLE_OAUTH_CALLBACK_URL=
JWT_SECRETS=
JWT_EXPIRES=
JWT_REFRESH_EXPIRES=
JWT_EMAIL_EXPIRES=
FRONTEND_URL=
GMAIL_USER=
GMAIL_PASS=
GOOGLE_OAUTH_CLIENT_ID=
GOOGLE_OAUTH_CLIENT_SECRET=
GOOGLE_OAUTH_CALLBACK_URL=
FIREBASE_TYPE=
FIREBASE_PROJECT_ID=
FIREBASE_PRIVATE_KEY_ID=
FIREBASE_PRIVATE_KEY=
FIREBASE_CLIENT_EMAIL=
FIREBASE_CLIENT_ID=
FIREBASE_AUTH_URI=
FIREBASE_TOKEN_URI=
FIREBASE_AUTH_PROVIDER_X509_CERT_URL=
FIREBASE_CLIENT_X509_CERT_URL=
JWT_REFRESH_EXPIRES=
NEWEBPAY_PAY_GATEWAY=
NEWEBPAY_VERSION=
NEWEBPAY_MERCHANT_ID=
NEWEBPAY_NOTIFY_URL=
MERCHANT_ID=
HASHKEY=
HASHIV=
VERSION=
RETURN_URL=
NOTIFY_URL=
PAY_GATEWAY=
LINEPAY_CHANNEL_ID=
LINEPAY_VERSION=
LINEPAY_CHANNEL_SECRET_KEY=
LINEPAY_SITE=
LINEPAY_RETURN_HOST=
LINEPAY_RETURN_CONFIRM_URL=
LINEPAY_RETURN_CANCEL_URL=
LINEPAY_CHANNEL_SECRET_KEY=
LINEPAY_SITE=
LINEPAY_VERSION=
SHARE_CODE_EXPIRES=
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ticket-System(票務系統)- 後端
# Movie Go(票務系統)- 後端

## 專案介紹

Expand Down Expand Up @@ -41,19 +41,29 @@
在瀏覽器中前往 `http://localhost:3000` 後,輸入對應身份組的帳號密碼即可查看

## 資料夾說明
| 資料夾/檔案 | 說明 |
|------------------|---------------------|
| `src/bin` | 內含server初始化入口www.ts |
| `src/config` | 此專案設定如DB連線資訊 |
| `src/controller` | 存放各功能controller |
| `src/middleware` | 存放專案使用的middleware |
| `src/models` | DB Schema 物件定義 |
| `src/routes` | 存放各功能路由 |
| `src/service` | 存放各功能業務邏輯 |
| `src/utils` | 全域共用的函式工具 |
| 資料夾/檔案 | 說明 |
|------------------|---------------------------------------|
| `src/bin` | 內含server初始化入口www.ts |
| `src/config` | 此專案設定如DB連線資訊 |
| `src/controller` | 存放各功能controller |
| `src/dto` | 存放專案使用的data transfer object |
| `src/middleware` | 存放專案使用的middleware |
| `src/models` | DB Schema 物件定義 |
| `src/repository` | 存放資料庫操作方法 |
| `src/routes` | 存放各功能路由 |
| `src/service` | 存放各功能業務邏輯 |
| `src/swagger` | 存放產生swagger文件所需object |
| `src/types` | 專案使用的types |
| `src/utils` | 全域共用的函式工具 |
| `src/validator` | express-validator 使用的 pipeline object |
| `src/vo` | 用於 response 的 view object |

## 專案使用技術
- Node.js: v21
- Express: v4.19
- TypeScript: v5
- ESlint: v8
- ESlint: v8
## 專案使用平台
- MongoDB Atlas
- GitHub Action CI/CD
- Google Cloud Platform - Cloud Run
11 changes: 6 additions & 5 deletions src/repository/ticketRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
} from '../utils/aggregate/ticket/getTickets.pipeline';
import { GetTicketDetailDto } from '../dto/ticket/getTicketDetailDto';
import { createGetTicketDetailPipeline } from '../utils/aggregate/ticket/getTicketDetail.pipeline';
import { SellTicketDto } from '../dto/ticket/sellTicketDto';
import { GetSharedTicketsDto } from '../dto/ticket/getSharedTicketsDto';

export class TicketRepository {
Expand Down Expand Up @@ -52,12 +51,14 @@ export class TicketRepository {
};

public findTransferableTicketByOrderIdAndProductId = async (
sellTicketDto: SellTicketDto,
userId: Types.ObjectId,
orderId: Types.ObjectId,
productId: Types.ObjectId,
) => {
return TicketModel.find({
userId: sellTicketDto.userId,
orderId: sellTicketDto.orderId,
productId: sellTicketDto.productId,
userId: userId,
orderId: orderId,
productId: productId,
isPublished: false,
status: TicketStatus.unverified,
expiredAt: { $gte: new Date() },
Expand Down
10 changes: 7 additions & 3 deletions src/service/ticketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ export class TicketService {
const product = (await this.productRepository.findById(
new Types.ObjectId(productId),
)) as IProduct;
const holdCount = order.products
.filter((product) => product.productId.toString() === productId)
.map((p) => p.amount)[0];
const tickets =
await this.ticketRepository.findTransferableTicketByOrderIdAndProductId(
order.userId,
order._id,
product._id,
);
const holdCount = tickets.length;
return new GetOrderInfoVo(holdCount, product);
};

Expand Down
4 changes: 3 additions & 1 deletion src/service/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ export class UserService {
public sellTicket = async (sellTicketDto: SellTicketDto) => {
const tickets =
await this.ticketRepository.findTransferableTicketByOrderIdAndProductId(
sellTicketDto,
sellTicketDto.userId,
sellTicketDto.orderId,
sellTicketDto.productId,
);
if (!tickets) {
throwError(
Expand Down

0 comments on commit 604bea8

Please sign in to comment.