Skip to content

Commit 184edda

Browse files
committed
fix: series update at
1 parent 2c8ea0f commit 184edda

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/graphql/series.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ export const resolvers: IResolvers<any, ApolloContext> = {
106106
const repo = getRepository(SeriesPosts);
107107
const count = await repo.count({
108108
where: {
109-
fk_series_id: parent.id
110-
}
109+
fk_series_id: parent.id,
110+
},
111111
});
112112
return count;
113-
}
113+
},
114114
},
115115
Query: {
116116
series: async (parent: any, { id, username, url_slug }: any, ctx) => {
@@ -138,7 +138,7 @@ export const resolvers: IResolvers<any, ApolloContext> = {
138138
.orderBy('name')
139139
.getMany();
140140
return seriesList;
141-
}
141+
},
142142
},
143143
Mutation: {
144144
createSeries: async (parent: any, args, ctx) => {
@@ -150,8 +150,8 @@ export const resolvers: IResolvers<any, ApolloContext> = {
150150
const exists = await seriesRepo.findOne({
151151
where: {
152152
url_slug,
153-
fk_user_id: ctx.user_id
154-
}
153+
fk_user_id: ctx.user_id,
154+
},
155155
});
156156
if (exists) {
157157
throw new ApolloError('URL Slug already exists', 'ALREADY_EXISTS');
@@ -165,16 +165,16 @@ export const resolvers: IResolvers<any, ApolloContext> = {
165165
},
166166
appendToSeries: async (parent, args, ctx) => {
167167
const { series_id, post_id } = args as AppendToSeriesArgs;
168-
await getSeriesIfValid(series_id, ctx.user_id);
168+
const series = await getSeriesIfValid(series_id, ctx.user_id);
169169

170170
const seriesPostsRepo = getRepository(SeriesPosts);
171171
const seriesPostsList = await seriesPostsRepo.find({
172172
where: {
173-
fk_series_id: series_id
173+
fk_series_id: series_id,
174174
},
175175
order: {
176-
index: 'ASC'
177-
}
176+
index: 'ASC',
177+
},
178178
});
179179
const exists = seriesPostsList.find(sp => sp.fk_post_id === post_id);
180180

@@ -193,15 +193,22 @@ export const resolvers: IResolvers<any, ApolloContext> = {
193193

194194
// save
195195
await seriesPostsRepo.save(seriesPosts);
196+
197+
// update series updated_at
198+
series.updated_at = new Date();
199+
const seriesRepo = getRepository(Series);
200+
await seriesRepo.save(series);
201+
196202
return nextIndex;
197203
},
198204
editSeries: async (parent, args, ctx) => {
199205
const { id, name, series_order } = args as EditSeriesArgs;
200206
const series = await getSeriesIfValid(id, ctx.user_id);
201-
// update series name
207+
// update series name and updated_at if needed
202208
if (name !== series.name) {
203209
const seriesRepo = getRepository(Series);
204210
series.name = name;
211+
series.updated_at = new Date();
205212
await seriesRepo.save(series);
206213
}
207214

@@ -210,8 +217,8 @@ export const resolvers: IResolvers<any, ApolloContext> = {
210217
const seriesPostsRepo = getRepository(SeriesPosts);
211218
const seriesPosts = await seriesPostsRepo.find({
212219
where: {
213-
fk_series_id: id
214-
}
220+
fk_series_id: id,
221+
},
215222
});
216223

217224
const valid =
@@ -231,7 +238,7 @@ export const resolvers: IResolvers<any, ApolloContext> = {
231238
// index mismatch
232239
acc.push({
233240
id: current,
234-
index: index + 1
241+
index: index + 1,
235242
});
236243
return acc;
237244
}
@@ -260,6 +267,6 @@ export const resolvers: IResolvers<any, ApolloContext> = {
260267
}
261268
await seriesRepo.remove(series);
262269
return true;
263-
}
264-
}
270+
},
271+
},
265272
};

0 commit comments

Comments
 (0)