diff --git a/src/app/user_session.ts b/src/app/user_session.ts index d3dfc1d..50e6a2b 100644 --- a/src/app/user_session.ts +++ b/src/app/user_session.ts @@ -23,7 +23,7 @@ const expireTicket = async ( ctx: restate.RpcContext, userId: string, ticketId: string, -) => { }; +) => {}; const checkout = async (ctx: restate.RpcContext, userId: string) => { return true; diff --git a/src/part2/ticket_service.ts b/src/part2/ticket_service.ts index 37d0de3..d5ddeda 100644 --- a/src/part2/ticket_service.ts +++ b/src/part2/ticket_service.ts @@ -19,7 +19,7 @@ enum TicketStatus { const reserve = async (ctx: restate.RpcContext) => { const status = - (await ctx.get("status")) || TicketStatus.Available; + (await ctx.get("status")) ?? TicketStatus.Available; if (status === TicketStatus.Available) { ctx.set("status", TicketStatus.Reserved); @@ -31,7 +31,7 @@ const reserve = async (ctx: restate.RpcContext) => { const unreserve = async (ctx: restate.RpcContext) => { const status = - (await ctx.get("status")) || TicketStatus.Available; + (await ctx.get("status")) ?? TicketStatus.Available; if (status === TicketStatus.Sold) { return false; @@ -43,7 +43,7 @@ const unreserve = async (ctx: restate.RpcContext) => { const markAsSold = async (ctx: restate.RpcContext) => { const status = - (await ctx.get("status")) || TicketStatus.Available; + (await ctx.get("status")) ?? TicketStatus.Available; if (status === TicketStatus.Reserved) { ctx.set("status", TicketStatus.Sold); diff --git a/src/part2/user_session.ts b/src/part2/user_session.ts index 67e2316..50a271d 100644 --- a/src/part2/user_session.ts +++ b/src/part2/user_session.ts @@ -21,7 +21,7 @@ const addTicket = async ( const reservationSuccess = await ctx.rpc(ticketServiceApi).reserve(ticketId); if (reservationSuccess) { - const tickets = (await ctx.get("tickets")) || []; + const tickets = (await ctx.get("tickets")) ?? []; tickets.push(ticketId); ctx.set("tickets", tickets); @@ -38,7 +38,7 @@ const expireTicket = async ( userId: string, ticketId: string, ) => { - const tickets = (await ctx.get("tickets")) || []; + const tickets = (await ctx.get("tickets")) ?? []; const ticketIndex = tickets.findIndex((ticket) => ticket === ticketId); @@ -51,9 +51,9 @@ const expireTicket = async ( }; const checkout = async (ctx: restate.RpcContext, userId: string) => { - const tickets = await ctx.get("tickets"); + const tickets = (await ctx.get("tickets")) ?? []; - if (tickets === null || tickets.length === 0) { + if (tickets.length === 0) { return false; } diff --git a/src/part3/ticket_service.ts b/src/part3/ticket_service.ts index 37d0de3..d5ddeda 100644 --- a/src/part3/ticket_service.ts +++ b/src/part3/ticket_service.ts @@ -19,7 +19,7 @@ enum TicketStatus { const reserve = async (ctx: restate.RpcContext) => { const status = - (await ctx.get("status")) || TicketStatus.Available; + (await ctx.get("status")) ?? TicketStatus.Available; if (status === TicketStatus.Available) { ctx.set("status", TicketStatus.Reserved); @@ -31,7 +31,7 @@ const reserve = async (ctx: restate.RpcContext) => { const unreserve = async (ctx: restate.RpcContext) => { const status = - (await ctx.get("status")) || TicketStatus.Available; + (await ctx.get("status")) ?? TicketStatus.Available; if (status === TicketStatus.Sold) { return false; @@ -43,7 +43,7 @@ const unreserve = async (ctx: restate.RpcContext) => { const markAsSold = async (ctx: restate.RpcContext) => { const status = - (await ctx.get("status")) || TicketStatus.Available; + (await ctx.get("status")) ?? TicketStatus.Available; if (status === TicketStatus.Reserved) { ctx.set("status", TicketStatus.Sold); diff --git a/src/part3/user_session.ts b/src/part3/user_session.ts index 0c430a8..1553e34 100644 --- a/src/part3/user_session.ts +++ b/src/part3/user_session.ts @@ -21,7 +21,7 @@ const addTicket = async ( const reservationSuccess = await ctx.rpc(ticketServiceApi).reserve(ticketId); if (reservationSuccess) { - const tickets = (await ctx.get("tickets")) || []; + const tickets = (await ctx.get("tickets")) ?? []; tickets.push(ticketId); ctx.set("tickets", tickets); @@ -38,7 +38,7 @@ const expireTicket = async ( userId: string, ticketId: string, ) => { - const tickets = (await ctx.get("tickets")) || []; + const tickets = (await ctx.get("tickets")) ?? []; const ticketIndex = tickets.findIndex((ticket) => ticket === ticketId); @@ -51,9 +51,9 @@ const expireTicket = async ( }; const checkout = async (ctx: restate.RpcContext, userId: string) => { - const tickets = await ctx.get("tickets"); + const tickets = (await ctx.get("tickets")) ?? []; - if (tickets && tickets.length > 0) { + if (tickets.length > 0) { const checkout_success = await ctx .rpc(checkoutApi) .checkout({ userId: userId, tickets: tickets! }); diff --git a/src/part4/ticket_service.ts b/src/part4/ticket_service.ts index 37d0de3..d5ddeda 100644 --- a/src/part4/ticket_service.ts +++ b/src/part4/ticket_service.ts @@ -19,7 +19,7 @@ enum TicketStatus { const reserve = async (ctx: restate.RpcContext) => { const status = - (await ctx.get("status")) || TicketStatus.Available; + (await ctx.get("status")) ?? TicketStatus.Available; if (status === TicketStatus.Available) { ctx.set("status", TicketStatus.Reserved); @@ -31,7 +31,7 @@ const reserve = async (ctx: restate.RpcContext) => { const unreserve = async (ctx: restate.RpcContext) => { const status = - (await ctx.get("status")) || TicketStatus.Available; + (await ctx.get("status")) ?? TicketStatus.Available; if (status === TicketStatus.Sold) { return false; @@ -43,7 +43,7 @@ const unreserve = async (ctx: restate.RpcContext) => { const markAsSold = async (ctx: restate.RpcContext) => { const status = - (await ctx.get("status")) || TicketStatus.Available; + (await ctx.get("status")) ?? TicketStatus.Available; if (status === TicketStatus.Reserved) { ctx.set("status", TicketStatus.Sold); diff --git a/src/part4/user_session.ts b/src/part4/user_session.ts index 84dba0c..0fe5f06 100644 --- a/src/part4/user_session.ts +++ b/src/part4/user_session.ts @@ -23,7 +23,7 @@ const addTicket = async ( if (reservation_success) { // add ticket to user session tickets - const tickets = (await ctx.get("tickets")) || []; + const tickets = (await ctx.get("tickets")) ?? []; tickets.push(ticketId); ctx.set("tickets", tickets); @@ -41,7 +41,7 @@ const expireTicket = async ( userId: string, ticketId: string, ) => { - const tickets = (await ctx.get("tickets")) || []; + const tickets = (await ctx.get("tickets")) ?? []; const index = tickets.findIndex((id) => id === ticketId); @@ -55,9 +55,9 @@ const expireTicket = async ( }; const checkout = async (ctx: restate.RpcContext, userId: string) => { - const tickets = await ctx.get("tickets"); + const tickets = (await ctx.get("tickets")) ?? []; - if (tickets && tickets.length > 0) { + if (tickets.length > 0) { const checkout_success = await ctx .rpc(checkoutApi) .checkout({ userId: userId, tickets: tickets! });