Skip to content

Commit

Permalink
Merge pull request #106 from Arios67/feat/#101
Browse files Browse the repository at this point in the history
소셜로그인, 경매 코드 수정
  • Loading branch information
Arios67 committed Apr 1, 2022
2 parents 77c4c87 + 57b1231 commit cba8eab
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
7 changes: 2 additions & 5 deletions ars/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ version: '3.3'

services:
my_backend:
platform: linux/x86_64
image: asia.gcr.io/artiful-a1/my_backend:1.9
build:
context: .
dockerfile: Dockerfile
env_file:
- ./.env.dev
ports:
- 3000:3000
volumes:
- ./src:/myfolder/src
- ./.env:/myfolder/.env

my_database:
platform: linux/x86_64
Expand All @@ -27,7 +24,7 @@ services:
cap_add:
- SYS_NICE
ports:
- 3306:3306
- 3307:3306

my_redis:
image: redis:6.2.6
Expand Down
8 changes: 5 additions & 3 deletions ars/src/apis/art/art.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export class ArtResolver {
console.log(redisValue);
return redisValue;
}

// 레디스에 캐시가 되어있지 않다면, 엘라스틱서치에서 조회하기(유저가 검색한 검색어로 조회하기)
const result = await this.elasticsearchService.search({
index: 'artipul',
Expand All @@ -68,6 +67,7 @@ export class ArtResolver {
instant_bid: el._source.instant_bid,
price: el._source.price,
deadline: el._source.deadline,
thumbnail: el._source.thumbnail,
tag1: el._source.tag1,
tag2: el._source.tag2,
tag3: el._source.tag3,
Expand All @@ -81,6 +81,7 @@ export class ArtResolver {
{ ttl: 0 },
);
// 최종 결과 브라우저에 리턴해주기

return artTags;
}

Expand All @@ -93,6 +94,7 @@ export class ArtResolver {
async fetchArtImages(@Args('artId') artId: string) {
return await this.artService.findImages({ artId });
}

///////////////////////////////////////////////////////////////////////////
@UseGuards(GqlAuthAccessGuard)
@Query(() => Number)
Expand Down Expand Up @@ -177,7 +179,7 @@ export class ArtResolver {
@Args('createArtInput') createArtInput: CreateArtInput, //
@CurrentUser() currentUser: ICurrentUser,
) {
//엘라스틱서치에서 등록할때 한번 사용 후 주석
// 엘라스틱서치에서 등록할때 한번 사용 후 주석
// const result = await this.elasticsearchService.create({
// id: 'artipulid',
// index: 'artipul',
Expand Down Expand Up @@ -209,7 +211,7 @@ export class ArtResolver {
@UseGuards(GqlAuthAccessGuard)
@Query(() => [Art])
async fetchLikeArt(
@Args('page') page: number,
@Args('page', { nullable: true }) page: number,
@CurrentUser() currentUser: ICurrentUser,
) {
return await this.likeArtService.find(currentUser.id, page);
Expand Down
7 changes: 4 additions & 3 deletions ars/src/apis/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class AuthService {
{ email: user.email, sub: user.id },
{ secret: process.env.REFRESH_TOKEN_KEY, expiresIn: '8h' },
);
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
res.setHeader('Access-Control-Allow-Origin', 'https://artipul.shop');
res.setHeader(
'Set-Cookie',
`refreshToken=${refreshToken}; path=/; domain=.daseul.shop; SameSite=None; Secure;httpOnly;`,
Expand All @@ -38,10 +38,11 @@ export class AuthService {
const createUser = { ...rest, password: hashedPassword };
user = await this.userService.create({ ...createUser });
this.setRefreshToken({ user, res });
res.redirect('/socialLogin');
res.redirect('https://artipul.shop/socialLogin');
} else {
this.setRefreshToken({ user, res });
res.redirect('');
res.redirect('https://artipul.shop/');
res.send(user);
}
}
}
16 changes: 11 additions & 5 deletions ars/src/apis/likeArt/likeArt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ export class LikeArtService {
) {}

async find(userId, page) {
const arts = await this.likeArtRepository.find({
take: 10,
skip: 10 * (page - 1),
where: { userId: userId },
});
let arts = [];
if (page) {
arts = await this.likeArtRepository.find({
take: 10,
skip: 10 * (page - 1),
where: { userId: userId },
});
} else {
arts = await this.likeArtRepository.find({ userId });
}

return arts.map((ele) => ele.art);
}

Expand Down
6 changes: 3 additions & 3 deletions ars/src/apis/payment/payment.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export class PaymentResolver {
const arts = await this.paymentService.checkTimeout();
arts.map(async (e) => {
const bidInfo = await this.cacheManager.get(e.id);
const price = bidInfo[0];
const bidder = await this.userService.findOne(bidInfo[1]);
if (price) {
if (bidInfo) {
const price = bidInfo[0];
const bidder = await this.userService.findOne(bidInfo[1]);
await this.paymentService.successfulBid(e.id, price, bidder, e.user);
} else {
await this.paymentService.failedBid(e.id);
Expand Down
15 changes: 8 additions & 7 deletions ars/src/apis/payment/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ export class PaymentService {

// 마감된 작품 체크
async checkTimeout() {
const time = new Date();
const yyyy = time.getFullYear();
const mm = time.getMonth() + 1;
const dd = time.getDate();
const currentTime = `${yyyy}-${mm}-${dd}`;

const utc = new Date();
const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
const currentTime = new Date(Number(utc) + Number(KR_TIME_DIFF));
console.log(currentTime, ' 현 재 시 간 ');
return await this.artRepository.find({
where: {
Expand Down Expand Up @@ -104,7 +101,11 @@ export class PaymentService {
// 입찰
async call(artId, bid_price, email) {
const art = await this.artRepository.findOne(artId);
const time = Number(art.deadline) - Number(new Date());

const utc = new Date();
const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
const currentTime = new Date(Number(utc) + Number(KR_TIME_DIFF));
const time = Number(art.deadline) - Number(currentTime);
if (time > 0) {
await this.cacheManager.set(artId, [bid_price, email], {
ttl: time + 60000,
Expand Down
5 changes: 5 additions & 0 deletions ars/src/apis/user/user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export class UserResolver {
return await this.userService.findUserEmail({ phoneNum });
}

@Query(() => String)
async findSocialUser(@Args('email') email: string) {
const user = await this.userService.findOne(email);
}

@Mutation(() => User)
async createUser(@Args('createUserInput') createUserInput: CreateUserInput) {
const { password, ...rest } = createUserInput;
Expand Down
3 changes: 2 additions & 1 deletion ars/src/common/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type Query {
fetchTransactionCompletedArts(page: Float!): [Art!]!
fetchEngaging(page: Float!): [Engage!]!
fetchArtistWorks(artId: String!): [Art!]!
fetchLikeArt(page: Float!): [Art!]!
fetchLikeArt(page: Float): [Art!]!
fetchBoard(boardId: String!): Board!
fetchBoardImgaes(boardId: String!): [BoardImage!]!
fetchBoards: [Board!]!
Expand All @@ -148,6 +148,7 @@ type Query {
fetchArtistProfile(artId: String!): Profile!
fetchUser: User!
findUserEmail(phoneNum: String!): String!
findSocialUser(email: String!): String!
fetchPointTransactions: [PointTransaction!]!
}

Expand Down

0 comments on commit cba8eab

Please sign in to comment.