Skip to content

Commit

Permalink
Merge pull request #59 from CudoVentures/cudos-dev
Browse files Browse the repository at this point in the history
Cudos dev
  • Loading branch information
SpaghettiOverload authored Oct 17, 2023
2 parents 444a1bb + 99dfd75 commit 3b35964
Show file tree
Hide file tree
Showing 72 changed files with 1,448 additions and 1,476 deletions.
22 changes: 13 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,20 @@ module.exports = {
"radix": 0,
"no-plusplus": "off",
"no-bitwise": "off",
"no-undef": [ "error" ],
"prefer-destructuring": [ "error", { "array": false, "object": false }, { "enforceForRenamedProperties": false } ],
"max-len": [ "error", { "code": 1000 } ],
"indent": [ "error", 4, { "SwitchCase": 1 } ],
"no-undef": ["error"],
"prefer-destructuring": ["error", { "array": false, "object": false }, { "enforceForRenamedProperties": false }],
"max-len": ["error", { "code": 1000 }],
"indent": ["error", 4, { "SwitchCase": 1 }],
"semi": "off",
"no-unused-vars": "off",
"no-console": [ "warn", { "allow": [ "log", "warn", "error" ] } ],
"no-empty": [ "error", { "allowEmptyCatch": true } ],
"@typescript-eslint/no-unused-vars": "off",
"no-console": ["warn", { "allow": ["log", "warn", "error"] }],
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-empty-function": ["error", {
"allow": ["constructors"]
}],
"no-fallthrough": "warn",
"quotes": [ "warn", "single" ],
"quotes": ["warn", "single"],
"one-var": "off",
"one-var-declaration-per-line": "off",
"nonblock-statement-body-position": "off",
Expand All @@ -74,12 +78,12 @@ module.exports = {
"no-multi-assign": "off",
"dot-notation": "off",
"newline-per-chained-call": "off",
"import/extensions": [ "error", "ignorePackages", {
"import/extensions": ["error", "ignorePackages", {
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
} ],
}],
"import/prefer-default-export": "off",
"max-classes-per-file": "off"
},
Expand Down
20 changes: 10 additions & 10 deletions apps/backend/src/allowlist/allowlist.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { Test, TestingModule } from '@nestjs/testing';
import { AllowlistController } from './allowlist.controller';

describe('AllowlistController', () => {
let controller: AllowlistController;
let controller: AllowlistController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AllowlistController],
}).compile();
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AllowlistController],
}).compile();

controller = module.get<AllowlistController>(AllowlistController);
});
controller = module.get<AllowlistController>(AllowlistController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
92 changes: 46 additions & 46 deletions apps/backend/src/allowlist/allowlist.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
Body,
Controller,
Get,
Param,
ParseIntPipe,
Post,
Put,
Req,
Request,
UnauthorizedException,
UseGuards,
UseInterceptors,
Body,
Controller,
Get,
Param,
ParseIntPipe,
Post,
Put,
Req,
Request,
UnauthorizedException,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { TransactionInterceptor } from '../common/common.interceptors';
Expand All @@ -30,20 +30,20 @@ import { SignedMessageDto } from './dto/signed-message.dto';
@ApiTags('Allowlist')
@Controller('allowlist')
export class AllowlistController {
constructor(private allowlistService: AllowlistService) { }
constructor(private allowlistService: AllowlistService) { }

@Get('all')
async findAll(): Promise<AllowlistEntity[]> {
return this.allowlistService.findAll();
}
async findAll(): Promise<AllowlistEntity[]> {
return this.allowlistService.findAll();
}

@Get(':allowlistId/user/joined')
async isUserJoinedAllowlist(
@Req() req,
@Param('allowlistId') allowlistId: number,
): Promise<boolean> {
const sessionUserId = req.session.user?.id as number
return this.allowlistService.isUserJoinedAllowlist(allowlistId, sessionUserId);
const sessionUserId = req.session.user?.id as number
return this.allowlistService.isUserJoinedAllowlist(allowlistId, sessionUserId);
}

@Get(':allowlistId/user/address/:address')
Expand All @@ -52,40 +52,40 @@ export class AllowlistController {
@Param('allowlistId') allowlistId: number,
@Param('address') address: string,
): Promise<{ userEntity: UserEntity }> {
const userEntity = await this.allowlistService.getUserByAllowlistIdAndAddress(allowlistId, address);
const userEntity = await this.allowlistService.getUserByAllowlistIdAndAddress(allowlistId, address);

return {
userEntity,
}
return {
userEntity,
}
}

@Get(':customId')
async findByCustomId(
@Param('customId') customId: string,
): Promise<AllowlistEntity> {
return this.allowlistService.findByCustomId(customId);
return this.allowlistService.findByCustomId(customId);
}

@Get('/id/:id')
async findById(
@Param('id', ParseIntPipe) id: number,
): Promise<{ allowlistEntity: AllowlistEntity }> {
const allowlistEntity = await this.allowlistService.findOne(id);
const allowlistEntity = await this.allowlistService.findOne(id);

return {
allowlistEntity,
}
return {
allowlistEntity,
}
}

@Get()
async findByAdmin(@Request() req): Promise<AllowlistEntity[]> {
return this.allowlistService.findByAdmin(req.session.user.address);
return this.allowlistService.findByAdmin(req.session.user.address);
}

@Get('entries/:id')
@UseGuards(IsAdminGuard)
async getEntries(@Param('id', ParseIntPipe) id: number) {
return this.allowlistService.getEntries(id);
return this.allowlistService.getEntries(id);
}

@UseInterceptors(TransactionInterceptor)
Expand All @@ -95,24 +95,24 @@ export class AllowlistController {
@Req() req,
@Body(SignMessagePipe) joinAllowlistDto: JoinAllowlistDto,
) {
const sessionUser = req.session.user
// update user record
const allowlistUser = await this.allowlistService.joinAllowlist(
id,
joinAllowlistDto.connectedAddress,
joinAllowlistDto.userEmail,
sessionUser,
);
return allowlistUser
const sessionUser = req.session.user
// update user record
const allowlistUser = await this.allowlistService.joinAllowlist(
id,
joinAllowlistDto.connectedAddress,
joinAllowlistDto.userEmail,
sessionUser,
);
return allowlistUser
}

@UseInterceptors(TransactionInterceptor)
@Post()
async create(
@Body(SignMessagePipe, CreateAllowlistPipe)
createAllowlistDto: CreateAllowlistDto,
createAllowlistDto: CreateAllowlistDto,
): Promise<AllowlistEntity> {
return this.allowlistService.createAllowlist(createAllowlistDto);
return this.allowlistService.createAllowlist(createAllowlistDto);
}

@UseInterceptors(TransactionInterceptor)
Expand All @@ -125,11 +125,11 @@ export class AllowlistController {
@Body(SignMessagePipe) signedData: SignedMessageDto,
@Body(EditAllowlistPipe) updateAllowlistDto: UpdateAllowlistDto,
): Promise<AllowlistEntity> {
// If we reach here, we are guarantied a valid allowlist admin in the session by the "IsAdminGuard"
// and valid signer by "SignMessagePipe". We only have to compare them.
if (req.session.user.address === signedData.connectedAddress) {
return this.allowlistService.updateAllowlist(id, updateAllowlistDto);
}
throw new UnauthorizedException('Invalid admin');
// If we reach here, we are guarantied a valid allowlist admin in the session by the "IsAdminGuard"
// and valid signer by "SignMessagePipe". We only have to compare them.
if (req.session.user.address === signedData.connectedAddress) {
return this.allowlistService.updateAllowlist(id, updateAllowlistDto);
}
throw new UnauthorizedException('Invalid admin');
}
}
8 changes: 4 additions & 4 deletions apps/backend/src/allowlist/allowlist.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { DiscordModule } from '../discord/discord.module';
import { TwitterModule } from '../twitter/twitter.module';

@Module({
imports: [SequelizeModule.forFeature([AllowlistRepo]), UserModule, DiscordModule, TwitterModule],
providers: [AllowlistService],
controllers: [AllowlistController],
exports: [SequelizeModule],
imports: [SequelizeModule.forFeature([AllowlistRepo]), UserModule, DiscordModule, TwitterModule],
providers: [AllowlistService],
controllers: [AllowlistController],
exports: [SequelizeModule],
})
export class AllowlistModule {}
20 changes: 10 additions & 10 deletions apps/backend/src/allowlist/allowlist.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { Test, TestingModule } from '@nestjs/testing';
import { AllowlistService } from './allowlist.service';

describe('AllowlistService', () => {
let service: AllowlistService;
let service: AllowlistService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AllowlistService],
}).compile();
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AllowlistService],
}).compile();

service = module.get<AllowlistService>(AllowlistService);
});
service = module.get<AllowlistService>(AllowlistService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
25 changes: 13 additions & 12 deletions apps/backend/src/allowlist/allowlist.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-shadow */
import { BadRequestException, Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/sequelize';
import axios from 'axios';
Expand All @@ -20,7 +21,7 @@ export class AllowlistService {
private allowlistRepo: typeof AllowlistRepo,
private userService: UserService,
private discordService: DiscordService,
private twitterService: TwitterService
private twitterService: TwitterService,
) { }

async getUserByAllowlistIdAndAddress(allowlistId: number, address: string): Promise<UserEntity> {
Expand Down Expand Up @@ -90,7 +91,7 @@ export class AllowlistService {
id: number,
updateCollectionDto: UpdateAllowlistDto,
): Promise<AllowlistEntity> {
const [count, [allowlistRepo]] = await this.allowlistRepo.update(
const [_count, [allowlistRepo]] = await this.allowlistRepo.update(
{ ...updateCollectionDto },
{ where: { id }, returning: true },
);
Expand All @@ -111,9 +112,8 @@ export class AllowlistService {
if (registeredUsers.includes(userId)) {
return allowlistEntity;
}
const updatedList = allowlistEntity.users.push(`${userId}`);

const [count, [updatedAllowlistRepo]] = await this.allowlistRepo.update(
const [_count, [updatedAllowlistRepo]] = await this.allowlistRepo.update(
{ users: allowlistEntity.users },
{ where: { id }, returning: true },
);
Expand Down Expand Up @@ -161,7 +161,7 @@ export class AllowlistService {
if (allowlistEntity.tweet_to_retweet) {
const retweeted = await this.twitterService.isTweetRetweeted(
allowlistEntity.tweet_to_retweet,
user.twitter_profile_id
user.twitter_profile_id,
);
if (!retweeted) {
throw new BadRequestException(`Criteria not met: ${TWITTER_API_MSGS.NotRetweetedTweet}`);
Expand Down Expand Up @@ -211,6 +211,7 @@ export class AllowlistService {
}),
);

// eslint-disable-next-line no-restricted-syntax
for (const u of users) {
if (
user.discord_profile_id
Expand Down Expand Up @@ -279,18 +280,18 @@ export class AllowlistService {
return {
id: user.id,
address: user.address,
email: user.email || "Not provided",
twitter_handle: user.twitter_profile_id || "Not provided",
discord_handle: user.discord_profile_id || "Not provided",
email: user.email || 'Not provided',
twitter_handle: user.twitter_profile_id || 'Not provided',
discord_handle: user.discord_profile_id || 'Not provided',
};
});
}),
);
}

async updateUserInfo(user, sessionUser) {
let sessionTwitterUser = sessionUser.twitter
let sessionDiscordUser = sessionUser.discord
const sessionTwitterUser = sessionUser.twitter
const sessionDiscordUser = sessionUser.discord

if (sessionTwitterUser) {
delete sessionTwitterUser.email
Expand All @@ -313,8 +314,8 @@ export class AllowlistService {
const newUser = {
...sessionDiscordUser,
...sessionTwitterUser,
address: user.address
address: user.address,
}
return await this.userService.updateUser(user.id, newUser)
return this.userService.updateUser(user.id, newUser)
}
}
Loading

0 comments on commit 3b35964

Please sign in to comment.