Skip to content

Commit 44f4479

Browse files
committed
Fix for wallet validation, added unique wallet/email check on create user, lower log level for sdk on prod
1 parent 68c43ee commit 44f4479

8 files changed

Lines changed: 40 additions & 8 deletions

File tree

backend/src/config/values.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export enum ValidatorErrorCode {
100100
EMAIL_OR_WALLET_REQUIRED = 422014,
101101
DATA_MODEL_STATUS_MISSING = 422100,
102102
DATA_MODEL_INVALID_STATUS = 422101,
103+
DUPLICATED_MAIL = 422102,
104+
DUPLICATED_WALLET = 422103,
103105
}
104106

105107
/**

backend/src/cron.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ export class Cron {
120120
apiUrl: env.APILLON_API_URL,
121121
key: env.APILLON_KEY,
122122
secret: env.APILLON_SECRET,
123-
logLevel: LogLevel.VERBOSE,
123+
logLevel:
124+
env.APP_ENV === 'production'
125+
? LogLevel.ERROR
126+
: LogLevel.VERBOSE,
124127
}).collection(env.COLLECTION_UUID)
125128
: null;
126129

backend/src/lib/claim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function claim(user: User): Promise<string> {
1010
apiUrl: env.APILLON_API_URL,
1111
key: env.APILLON_KEY,
1212
secret: env.APILLON_SECRET,
13-
logLevel: LogLevel.VERBOSE,
13+
logLevel: env.APP_ENV === 'production' ? LogLevel.ERROR : LogLevel.VERBOSE,
1414
}).collection(env.COLLECTION_UUID);
1515

1616
validateAirdropStatus(user.airdrop_status);

backend/src/lib/job.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ const sendClaimEmails = async (job: JobType, mysql: MySql) => {
9696
apiUrl: env.APILLON_API_URL,
9797
key: env.APILLON_KEY,
9898
secret: env.APILLON_SECRET,
99-
logLevel: LogLevel.VERBOSE,
99+
logLevel:
100+
env.APP_ENV === 'production' ? LogLevel.ERROR : LogLevel.VERBOSE,
100101
}).collection(env.COLLECTION_UUID)
101102
: null;
102103

backend/src/models/user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ export class User extends BaseSqlModel {
208208
`
209209
SELECT 1
210210
FROM user
211-
WHERE email <> @email
211+
WHERE id <> @id
212212
AND wallet = @wallet;
213213
`,
214214
{
215-
email: this.email,
215+
id: this.id,
216216
wallet: this.wallet,
217217
},
218218
);

backend/src/routes/create-user.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Application } from 'express';
22
import { NextFunction, Request, Response } from '../http';
3-
import { PopulateStrategy } from '../config/values';
3+
import { PopulateStrategy, ValidatorErrorCode } from '../config/values';
44
import { AuthenticateAdmin } from '../middlewares/authentication';
55
import { BatchUsers } from '../models/batch-users';
6-
import { ValidationError } from '../lib/errors';
6+
import { ResourceError, ValidationError } from '../lib/errors';
77

88
/**
99
* Installs new route on the provided application.
@@ -21,6 +21,30 @@ export function inject(app: Application) {
2121

2222
export async function resolve(req: Request, res: Response): Promise<void> {
2323
const { context, body } = req;
24+
25+
const usersToCreate = body.users;
26+
27+
const emailSet = new Set<string>();
28+
const walletSet = new Set<string>();
29+
30+
for (const user of usersToCreate) {
31+
const { email, wallet } = user;
32+
33+
if (email && emailSet.has(email)) {
34+
throw new ResourceError(ValidatorErrorCode.DUPLICATED_MAIL);
35+
}
36+
if (wallet && walletSet.has(wallet)) {
37+
throw new ResourceError(ValidatorErrorCode.DUPLICATED_WALLET);
38+
}
39+
40+
if (email) {
41+
emailSet.add(email);
42+
}
43+
if (wallet) {
44+
walletSet.add(wallet);
45+
}
46+
}
47+
2448
const users = new BatchUsers({}, context).populate(
2549
body,
2650
PopulateStrategy.ADMIN,

backend/src/scripts/dev/deploy-collection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { env } from '../../config/env';
66
apiUrl: env.APILLON_API_URL,
77
key: env.APILLON_KEY,
88
secret: env.APILLON_SECRET,
9-
logLevel: LogLevel.VERBOSE,
9+
logLevel: env.APP_ENV === 'production' ? LogLevel.ERROR : LogLevel.VERBOSE,
1010
});
1111

1212
const collection = await nft.create({

frontend/lib/misc/errors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export const ErrorCodes = {
8484
422007: 'Captcha error. Please solve the captcha again.',
8585
422008: 'User has already minted. Duplicate minting is not allowed.',
8686
422009: 'User with this wallet address already exists. Please use a different wallet.',
87+
422102: "Email is duplicated in the request. Please provide unique emails.",
88+
422103: "Wallet address is duplicated in the request. Please provide unique wallet addresses.",
8789
422013: 'Wallet address is not valid.',
8890
422014: 'Email or wallet address is required. Please provide one of them.',
8991

0 commit comments

Comments
 (0)