Skip to content

Commit

Permalink
feat: switch to mongo db
Browse files Browse the repository at this point in the history
  • Loading branch information
okjodom committed Nov 8, 2024
1 parent af2edd8 commit abc4d18
Show file tree
Hide file tree
Showing 47 changed files with 417 additions and 10,930 deletions.
8 changes: 1 addition & 7 deletions apps/swap/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ COPY package.json ./
COPY bun.lockb ./
COPY tsconfig.json tsconfig.json
COPY nest-cli.json nest-cli.json
COPY apps/swap/prisma/client ./prisma/client

# FIXME: This hack allows prisma to work with oven/bun
# Ref: https://github.com/oven-sh/bun/issues/5320#issuecomment-1730927088
COPY --from=node:20 /usr/local/bin/node /usr/local/bin/node

COPY apps/swap apps/swap
COPY libs libs
Expand All @@ -33,6 +28,5 @@ RUN bun install --production

COPY --from=development /usr/src/app/dist ./dist
COPY --from=development /usr/src/app/proto ./proto
COPY --from=development /usr/src/app/prisma ./prisma

CMD ["sh", "-c", "bun run prisma migrate deploy && bun run dist/apps/swap/main.js"]
CMD ["sh", "-c", "bun run dist/apps/swap/main.js"]
5 changes: 5 additions & 0 deletions apps/swap/db/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './onramp.schema';
export * from './onramp.repository';
export * from './offramp.schema';
export * from './offramp.repository';
export * from './types';
17 changes: 17 additions & 0 deletions apps/swap/db/offramp.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Model } from 'mongoose';
import { InjectModel } from '@nestjs/mongoose';
import { Injectable, Logger } from '@nestjs/common';
import { AbstractRepository } from '@bitsacco/common';
import { MpesaOfframpSwapDocument } from './offramp.schema';

@Injectable()
export class MpesaOfframpSwapRepository extends AbstractRepository<MpesaOfframpSwapDocument> {
protected readonly logger = new Logger(MpesaOfframpSwapRepository.name);

constructor(
@InjectModel(MpesaOfframpSwapDocument.name)
reservationModel: Model<MpesaOfframpSwapDocument>,
) {
super(reservationModel);
}
}
44 changes: 44 additions & 0 deletions apps/swap/db/offramp.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { AbstractDocument } from '@bitsacco/common';
import { SwapTransactionState } from './types';

@Schema({ versionKey: false })
export class MpesaOfframpSwapDocument extends AbstractDocument {
@Prop({
type: String,
enum: Object.values(SwapTransactionState),
required: true,
})
state: string;

@Prop({ type: String, required: true })
reference: string;

@Prop({ type: String, required: true })
lightning: string;

@Prop({ type: String, required: true })
phone: string;

@Prop({ type: String, required: false })
paymentTracker?: string;

@Prop({ type: String, required: true })
rate: string;

@Prop({ type: String, required: true })
amountSats: string;

@Prop({ type: Number, required: true })
retryCount: number;
}

export const MpesaOfframpSwapSchema = SchemaFactory.createForClass(
MpesaOfframpSwapDocument,
);

// Ensure uniqueness only when paymentTracker is not null
MpesaOfframpSwapSchema.index(
{ paymentTracker: 1 },
{ unique: true, sparse: true },
);
17 changes: 17 additions & 0 deletions apps/swap/db/onramp.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Model } from 'mongoose';
import { InjectModel } from '@nestjs/mongoose';
import { Injectable, Logger } from '@nestjs/common';
import { AbstractRepository } from '@bitsacco/common';
import { MpesaOnrampSwapDocument } from './onramp.schema';

@Injectable()
export class MpesaOnrampSwapRepository extends AbstractRepository<MpesaOnrampSwapDocument> {
protected readonly logger = new Logger(MpesaOnrampSwapRepository.name);

constructor(
@InjectModel(MpesaOnrampSwapDocument.name)
reservationModel: Model<MpesaOnrampSwapDocument>,
) {
super(reservationModel);
}
}
41 changes: 41 additions & 0 deletions apps/swap/db/onramp.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { AbstractDocument } from '@bitsacco/common';
import { SwapTransactionState } from './types';

@Schema({ versionKey: false })
export class MpesaOnrampSwapDocument extends AbstractDocument {
@Prop({
type: String,
enum: Object.values(SwapTransactionState),
required: true,
})
state: SwapTransactionState;

@Prop({ type: String, required: true })
reference: string;

@Prop({ type: String, required: true })
lightning: string;

@Prop({ type: String, required: false })
collectionTracker?: string;

@Prop({ type: String, required: true })
rate: string;

@Prop({ type: String, required: true })
amountSats: string;

@Prop({ type: Number, required: true })
retryCount: number;
}

export const MpesaOnrampSwapSchema = SchemaFactory.createForClass(
MpesaOnrampSwapDocument,
);

// Ensure uniqueness only when collectionTracker is not null
MpesaOnrampSwapSchema.index(
{ collectionTracker: 1 },
{ unique: true, sparse: true },
);
7 changes: 7 additions & 0 deletions apps/swap/db/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum SwapTransactionState {
PENDING = 'PENDING',
PROCESSING = 'PROCESSING',
FAILED = 'FAILED',
COMPLETE = 'COMPLETE',
RETRY = 'RETRY',
}
1 change: 0 additions & 1 deletion apps/swap/prisma/client/default.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/swap/prisma/client/default.js

This file was deleted.

1 change: 0 additions & 1 deletion apps/swap/prisma/client/edge.d.ts

This file was deleted.

224 changes: 0 additions & 224 deletions apps/swap/prisma/client/edge.js

This file was deleted.

Loading

0 comments on commit abc4d18

Please sign in to comment.