Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Replace || with ??
Browse files Browse the repository at this point in the history
  • Loading branch information
tillrohrmann committed Aug 21, 2023
1 parent fce64b0 commit 8597b26
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/app/user_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const expireTicket = async (
ctx: restate.RpcContext,
userId: string,
ticketId: string,
) => { };
) => {};

const checkout = async (ctx: restate.RpcContext, userId: string) => {
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/part2/ticket_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum TicketStatus {

const reserve = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Available) {
ctx.set("status", TicketStatus.Reserved);
Expand All @@ -31,7 +31,7 @@ const reserve = async (ctx: restate.RpcContext) => {

const unreserve = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Sold) {
return false;
Expand All @@ -43,7 +43,7 @@ const unreserve = async (ctx: restate.RpcContext) => {

const markAsSold = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Reserved) {
ctx.set("status", TicketStatus.Sold);
Expand Down
8 changes: 4 additions & 4 deletions src/part2/user_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const addTicket = async (
const reservationSuccess = await ctx.rpc(ticketServiceApi).reserve(ticketId);

if (reservationSuccess) {
const tickets = (await ctx.get<string[]>("tickets")) || [];
const tickets = (await ctx.get<string[]>("tickets")) ?? [];
tickets.push(ticketId);
ctx.set("tickets", tickets);

Expand All @@ -38,7 +38,7 @@ const expireTicket = async (
userId: string,
ticketId: string,
) => {
const tickets = (await ctx.get<string[]>("tickets")) || [];
const tickets = (await ctx.get<string[]>("tickets")) ?? [];

const ticketIndex = tickets.findIndex((ticket) => ticket === ticketId);

Expand All @@ -51,9 +51,9 @@ const expireTicket = async (
};

const checkout = async (ctx: restate.RpcContext, userId: string) => {
const tickets = await ctx.get<string[]>("tickets");
const tickets = (await ctx.get<string[]>("tickets")) ?? [];

if (tickets === null || tickets.length === 0) {
if (tickets.length === 0) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/part3/ticket_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum TicketStatus {

const reserve = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Available) {
ctx.set("status", TicketStatus.Reserved);
Expand All @@ -31,7 +31,7 @@ const reserve = async (ctx: restate.RpcContext) => {

const unreserve = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Sold) {
return false;
Expand All @@ -43,7 +43,7 @@ const unreserve = async (ctx: restate.RpcContext) => {

const markAsSold = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Reserved) {
ctx.set("status", TicketStatus.Sold);
Expand Down
8 changes: 4 additions & 4 deletions src/part3/user_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const addTicket = async (
const reservationSuccess = await ctx.rpc(ticketServiceApi).reserve(ticketId);

if (reservationSuccess) {
const tickets = (await ctx.get<string[]>("tickets")) || [];
const tickets = (await ctx.get<string[]>("tickets")) ?? [];
tickets.push(ticketId);
ctx.set("tickets", tickets);

Expand All @@ -38,7 +38,7 @@ const expireTicket = async (
userId: string,
ticketId: string,
) => {
const tickets = (await ctx.get<string[]>("tickets")) || [];
const tickets = (await ctx.get<string[]>("tickets")) ?? [];

const ticketIndex = tickets.findIndex((ticket) => ticket === ticketId);

Expand All @@ -51,9 +51,9 @@ const expireTicket = async (
};

const checkout = async (ctx: restate.RpcContext, userId: string) => {
const tickets = await ctx.get<string[]>("tickets");
const tickets = (await ctx.get<string[]>("tickets")) ?? [];

if (tickets && tickets.length > 0) {
if (tickets.length > 0) {
const checkout_success = await ctx
.rpc(checkoutApi)
.checkout({ userId: userId, tickets: tickets! });
Expand Down
6 changes: 3 additions & 3 deletions src/part4/ticket_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum TicketStatus {

const reserve = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Available) {
ctx.set("status", TicketStatus.Reserved);
Expand All @@ -31,7 +31,7 @@ const reserve = async (ctx: restate.RpcContext) => {

const unreserve = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Sold) {
return false;
Expand All @@ -43,7 +43,7 @@ const unreserve = async (ctx: restate.RpcContext) => {

const markAsSold = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Reserved) {
ctx.set("status", TicketStatus.Sold);
Expand Down
8 changes: 4 additions & 4 deletions src/part4/user_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const addTicket = async (

if (reservation_success) {
// add ticket to user session tickets
const tickets = (await ctx.get<string[]>("tickets")) || [];
const tickets = (await ctx.get<string[]>("tickets")) ?? [];
tickets.push(ticketId);
ctx.set("tickets", tickets);

Expand All @@ -41,7 +41,7 @@ const expireTicket = async (
userId: string,
ticketId: string,
) => {
const tickets = (await ctx.get<string[]>("tickets")) || [];
const tickets = (await ctx.get<string[]>("tickets")) ?? [];

const index = tickets.findIndex((id) => id === ticketId);

Expand All @@ -55,9 +55,9 @@ const expireTicket = async (
};

const checkout = async (ctx: restate.RpcContext, userId: string) => {
const tickets = await ctx.get<string[]>("tickets");
const tickets = (await ctx.get<string[]>("tickets")) ?? [];

if (tickets && tickets.length > 0) {
if (tickets.length > 0) {
const checkout_success = await ctx
.rpc(checkoutApi)
.checkout({ userId: userId, tickets: tickets! });
Expand Down

0 comments on commit 8597b26

Please sign in to comment.